From 5add1674ee031eaada9d19d07dde5efbd071b4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 30 Sep 2014 16:34:14 +0200 Subject: GameScreen: fix cam.unproject() after resize --- core/src/ch/asynk/tankontank/screens/GameScreen.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java index 6169509..2669e70 100644 --- a/core/src/ch/asynk/tankontank/screens/GameScreen.java +++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java @@ -144,7 +144,7 @@ public class GameScreen implements Screen float deltaY = ((dragPos.y - y) * cam.zoom * screenToViewport.y); dragPos.set(x, y); if (map.drag(deltaX, deltaY)) { - cam.unproject(touchPos.set(x, y, 0)); + unproject(x, y, touchPos); map.getHexAt(cell, touchPos.x, touchPos.y); } else { cam.translate(-deltaX, -deltaY, 0); @@ -157,16 +157,17 @@ public class GameScreen implements Screen { if (button == Input.Buttons.LEFT) { dragPos.set(x, y); - cam.unproject(touchPos.set(x, y, 0)); + unproject(x, y, touchPos); map.touchDown(touchPos.x, touchPos.y); } + return true; } @Override public boolean touchUp(int x, int y, int pointer, int button) { if (button == Input.Buttons.LEFT) { - cam.unproject(touchPos.set(x, y, 0)); + unproject(x, y, touchPos); map.touchUp(touchPos.x, touchPos.y); } return true; @@ -184,6 +185,11 @@ public class GameScreen implements Screen return multiplexer; } + private void unproject(int x, int y, Vector3 v) + { + cam.unproject(v.set(x, y, 0), mapViewport.getScreenX(), mapViewport.getScreenY(), mapViewport.getScreenWidth(), mapViewport.getScreenHeight()); + } + private void clampCameraPos() { float cx = cam.viewportWidth * cam.zoom / 2f; -- cgit v1.1-2-g2b99