From 16b4d05cac5b0b9babf8b22eb3e2e01ece5f6352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 2 Jul 2018 11:18:09 +0200 Subject: 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 --- core/src/ch/asynk/zproject/screens/GameCamera.java | 1 - 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; -- cgit v1.1-2-g2b99