forked from jzitnik/twodcraft
Added lazy loading of resources. The resource was previously loaded on each render, but now it is loaded the first time it is used and stays in memory.
29 lines
707 B
Java
29 lines
707 B
Java
package cz.jzitnik.game.sprites;
|
|
|
|
import cz.jzitnik.tui.Sprite;
|
|
|
|
import java.util.HashMap;
|
|
|
|
public class TwoBlockSprite extends Sprite<TwoBlockSprite.TwoBlockSpriteState> {
|
|
public enum TwoBlockSpriteState {
|
|
TOP, BOTTOM
|
|
}
|
|
|
|
public TwoBlockSprite(String top, String bottom) {
|
|
loadResources(new HashMap<>() {
|
|
{
|
|
put(TwoBlockSpriteState.TOP, top);
|
|
put(TwoBlockSpriteState.BOTTOM, bottom);
|
|
}
|
|
}, TwoBlockSpriteState.class);
|
|
}
|
|
|
|
public String getSprite() {
|
|
return getResource(TwoBlockSpriteState.TOP);
|
|
}
|
|
|
|
public String getSprite(TwoBlockSpriteState state) {
|
|
return getResource(state);
|
|
}
|
|
}
|