diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/zproject/Assets.java | 41 | ||||
-rw-r--r-- | core/src/ch/asynk/zproject/Board.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/zproject/Hud.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/zproject/ZProject.java | 8 | ||||
-rw-r--r-- | core/src/ch/asynk/zproject/screens/GameScreen.java | 4 |
5 files changed, 55 insertions, 6 deletions
diff --git a/core/src/ch/asynk/zproject/Assets.java b/core/src/ch/asynk/zproject/Assets.java new file mode 100644 index 0000000..3eadf9f --- /dev/null +++ b/core/src/ch/asynk/zproject/Assets.java @@ -0,0 +1,41 @@ +package ch.asynk.zproject; + +import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; + +public class Assets extends AssetManager implements Disposable +{ + public static final String CORNER = "data/corner.png"; + public static final String MAP_00 = "data/map_00.png"; + + @Override public void dispose() + { + ZProject.debug("diagnostics:\n" + getDiagnostics() ); + clear(); + super.dispose(); + } + + public Texture getTexture(String assetName) + { + return get(assetName, Texture.class); + } + + public TextureAtlas getAtlas(String assetName) + { + return get(assetName, TextureAtlas.class); + } + + public void loadGame() + { + load(MAP_00, Texture.class); + load(CORNER, Texture.class); + } + + public void unloadGame() + { + unload(MAP_00); + unload(CORNER); + } +} diff --git a/core/src/ch/asynk/zproject/Board.java b/core/src/ch/asynk/zproject/Board.java index a9badbd..0e4cfb9 100644 --- a/core/src/ch/asynk/zproject/Board.java +++ b/core/src/ch/asynk/zproject/Board.java @@ -9,9 +9,9 @@ public class Board implements Disposable { private final Texture map; - public Board() + public Board(final Assets assets) { - this.map = new Texture("data/map_00.png"); + this.map = assets.getTexture(assets.MAP_00); } @Override public void dispose() diff --git a/core/src/ch/asynk/zproject/Hud.java b/core/src/ch/asynk/zproject/Hud.java index ded7981..38728c0 100644 --- a/core/src/ch/asynk/zproject/Hud.java +++ b/core/src/ch/asynk/zproject/Hud.java @@ -10,9 +10,9 @@ public class Hud implements Disposable { private final Sprite hud; - public Hud() + public Hud(final Assets assets) { - this.hud = new Sprite(new Texture("data/corner.png")); + this.hud = new Sprite(assets.getTexture(assets.CORNER)); } @Override public void dispose() diff --git a/core/src/ch/asynk/zproject/ZProject.java b/core/src/ch/asynk/zproject/ZProject.java index cd25e65..12dc982 100644 --- a/core/src/ch/asynk/zproject/ZProject.java +++ b/core/src/ch/asynk/zproject/ZProject.java @@ -17,6 +17,8 @@ public class ZProject extends Game } private State state; + public final Assets assets = new Assets(); + @Override public void create() { this.state = State.NONE; @@ -28,6 +30,7 @@ public class ZProject extends Game @Override public void dispose() { switchToNone(); + assets.dispose(); } public static void error(String msg) @@ -51,6 +54,9 @@ public class ZProject extends Game error("switch from and to " + state); return; } + switch(state) { + case GAME: assets.unloadGame(); break; + } if (state != State.NONE) { getScreen().dispose(); } @@ -65,6 +71,8 @@ public class ZProject extends Game public void switchToGame() { + assets.loadGame(); + assets.finishLoading(); switchTo(new GameScreen(this), State.GAME); } } diff --git a/core/src/ch/asynk/zproject/screens/GameScreen.java b/core/src/ch/asynk/zproject/screens/GameScreen.java index 425c737..189219d 100644 --- a/core/src/ch/asynk/zproject/screens/GameScreen.java +++ b/core/src/ch/asynk/zproject/screens/GameScreen.java @@ -40,8 +40,8 @@ public class GameScreen implements Screen public GameScreen(final ZProject zproject) { this.zproject = zproject; - this.hud = new Hud(); - this.board = new Board(); + this.hud = new Hud(zproject.assets); + this.board = new Board(zproject.assets); this.batch = new SpriteBatch(); this.camera = new GameCamera(10, board.getWidth(), board.getHeight(), 1.0f, 0.3f, false); Gdx.input.setInputProcessor(getMultiplexer()); |