From 9507c5fcce6f5b41b167ce200692111b00457600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 30 Sep 2014 16:29:16 +0200 Subject: GameScreen: add virtualWidth, virtualHeight --- core/src/ch/asynk/tankontank/screens/GameScreen.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java index 82a92a0..6169509 100644 --- a/core/src/ch/asynk/tankontank/screens/GameScreen.java +++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java @@ -46,6 +46,8 @@ public class GameScreen implements Screen private static final int DRAGGED_Z_INDEX = 10; private float maxZoomOut; + private float virtualWidth; + private float virtualHeight; private final OrthographicCamera cam; private final FitViewport mapViewport; @@ -76,11 +78,13 @@ public class GameScreen implements Screen fps.setPosition( 10, Gdx.graphics.getHeight() - 40); map = factory.getMap(game.manager, GameFactory.MapType.MAP_A); + virtualWidth = map.getWidth(); + virtualHeight = map.getHeight(); mapBatch = new SpriteBatch(); - cam = new OrthographicCamera(); + cam = new OrthographicCamera(virtualWidth, virtualHeight); cam.setToOrtho(false); - mapViewport = new FitViewport(map.getWidth(), map.getHeight(), cam); + mapViewport = new FitViewport(virtualWidth, virtualHeight, cam); mapViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); debugShapes = new ShapeRenderer(); @@ -184,8 +188,8 @@ public class GameScreen implements Screen { float cx = cam.viewportWidth * cam.zoom / 2f; float cy = cam.viewportHeight * cam.zoom / 2f; - cam.position.x = MathUtils.clamp(cam.position.x, cx, (map.getWidth() - cx)); - cam.position.y = MathUtils.clamp(cam.position.y, cy, (map.getHeight() - cy)); + cam.position.x = MathUtils.clamp(cam.position.x, cx, (virtualWidth - cx)); + cam.position.y = MathUtils.clamp(cam.position.y, cy, (virtualHeight - cy)); } @Override -- cgit v1.1-2-g2b99