diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-06-28 16:24:06 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-06-28 16:24:06 +0200 |
commit | afa5db087cb0fc28223712cfc4ac4612504bdd69 (patch) | |
tree | 8575070b58c49ecae2f1a43fb0dae919f2df4c3d /core/src/ch/asynk/zproject/ZProject.java | |
parent | dd3232a74ab4b5f0d353d717cf3f080a73528a6e (diff) | |
download | gdx-boardgame-afa5db087cb0fc28223712cfc4ac4612504bdd69.zip gdx-boardgame-afa5db087cb0fc28223712cfc4ac4612504bdd69.tar.gz |
implement GameScreen and GameCamera
Diffstat (limited to 'core/src/ch/asynk/zproject/ZProject.java')
-rw-r--r-- | core/src/ch/asynk/zproject/ZProject.java | 95 |
1 files changed, 66 insertions, 29 deletions
diff --git a/core/src/ch/asynk/zproject/ZProject.java b/core/src/ch/asynk/zproject/ZProject.java index 11764d6..cd25e65 100644 --- a/core/src/ch/asynk/zproject/ZProject.java +++ b/core/src/ch/asynk/zproject/ZProject.java @@ -1,33 +1,70 @@ package ch.asynk.zproject; -import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; - -public class ZProject extends ApplicationAdapter { - SpriteBatch batch; - Texture img; - - @Override - public void create () { - batch = new SpriteBatch(); - img = new Texture("badlogic.jpg"); - } - - @Override - public void render () { - Gdx.gl.glClearColor(1, 0, 0, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - batch.begin(); - batch.draw(img, 0, 0); - batch.end(); - } - - @Override - public void dispose () { - batch.dispose(); - img.dispose(); - } +import com.badlogic.gdx.Screen; + +import ch.asynk.zproject.screens.GameScreen; + +public class ZProject extends Game +{ + public static final String DOM = "ZProject"; + + private enum State + { + NONE, + GAME + } + private State state; + + @Override public void create() + { + this.state = State.NONE; + Gdx.app.setLogLevel(Gdx.app.LOG_DEBUG); + debug(String.format("create() [%d;%d] %f", Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Gdx.graphics.getDensity())); + switchToGame(); + } + + @Override public void dispose() + { + switchToNone(); + } + + public static void error(String msg) + { + Gdx.app.error(DOM, msg); + } + + public static void debug(String msg) + { + Gdx.app.debug(DOM, msg); + } + + public static void debug(String from, String msg) + { + Gdx.app.debug(DOM, String.format("%s : %s", from, msg)); + } + + private void switchTo(Screen nextScreen, State nextState) + { + if (state == nextState) { + error("switch from and to " + state); + return; + } + if (state != State.NONE) { + getScreen().dispose(); + } + setScreen(nextScreen); + this.state = nextState; + } + + public void switchToNone() + { + switchTo(null, State.NONE); + } + + public void switchToGame() + { + switchTo(new GameScreen(this), State.GAME); + } } |