diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-07-02 11:18:09 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-07-02 11:18:09 +0200 |
commit | 16b4d05cac5b0b9babf8b22eb3e2e01ece5f6352 (patch) | |
tree | 1dcefac47f235ee8cf48adceac659eeeeab5c049 | |
parent | 7fad3866f825567984dfe60cb75c2ccdb3fcd4cf (diff) | |
download | gdx-boardgame-16b4d05cac5b0b9babf8b22eb3e2e01ece5f6352.zip gdx-boardgame-16b4d05cac5b0b9babf8b22eb3e2e01ece5f6352.tar.gz |
GameScreen : input triggers Screen.zoom instead of Camera.zoom
- let the screen handle the zoom factor change
- it forwards it to the camera
- and then call resize
-rw-r--r-- | core/src/ch/asynk/zproject/screens/GameCamera.java | 1 | ||||
-rw-r--r-- | core/src/ch/asynk/zproject/screens/GameScreen.java | 16 |
2 files changed, 11 insertions, 6 deletions
diff --git a/core/src/ch/asynk/zproject/screens/GameCamera.java b/core/src/ch/asynk/zproject/screens/GameCamera.java index e735bb5..54b1f82 100644 --- a/core/src/ch/asynk/zproject/screens/GameCamera.java +++ b/core/src/ch/asynk/zproject/screens/GameCamera.java @@ -128,7 +128,6 @@ public class GameCamera extends OrthographicCamera { zoom += dz; clampZoom(); - updateViewport(screenWidth, screenHeight); // zoom impacts viewport } public void clampZoom() diff --git a/core/src/ch/asynk/zproject/screens/GameScreen.java b/core/src/ch/asynk/zproject/screens/GameScreen.java index 189219d..8447f12 100644 --- a/core/src/ch/asynk/zproject/screens/GameScreen.java +++ b/core/src/ch/asynk/zproject/screens/GameScreen.java @@ -44,7 +44,7 @@ public class GameScreen implements Screen 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()); + Gdx.input.setInputProcessor(getMultiplexer(this)); this.paused = false; this.inputDelay = 0f; this.inputBlocked = false; @@ -114,13 +114,19 @@ public class GameScreen implements Screen resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } - private InputMultiplexer getMultiplexer() + private void zoom(float dz) + { + camera.zoom(dz); + resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + } + + private InputMultiplexer getMultiplexer(final GameScreen screen) { final InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(new InputAdapter() { @Override public boolean scrolled(int amount) { - camera.zoom(amount * ZOOM_SCROLL_FACTOR); + screen.zoom(amount * ZOOM_SCROLL_FACTOR); return true; } @Override public boolean touchDown(int x, int y, int pointer, int button) @@ -148,9 +154,9 @@ public class GameScreen implements Screen @Override public boolean zoom(float initialDistance, float distance) { if (initialDistance > distance) - camera.zoom(ZOOM_GESTURE_FACTOR); + screen.zoom(ZOOM_GESTURE_FACTOR); else - camera.zoom(-ZOOM_GESTURE_FACTOR); + screen.zoom(-ZOOM_GESTURE_FACTOR); inputBlocked = true; inputDelay = INPUT_DELAY; return true; |