diff options
-rw-r--r-- | core/src/ch/asynk/creepingarmor/screens/GameCamera.java | 33 | ||||
-rw-r--r-- | core/src/ch/asynk/creepingarmor/screens/GameScreen.java | 5 |
2 files changed, 30 insertions, 8 deletions
diff --git a/core/src/ch/asynk/creepingarmor/screens/GameCamera.java b/core/src/ch/asynk/creepingarmor/screens/GameCamera.java index 9392c5d..9fa123f 100644 --- a/core/src/ch/asynk/creepingarmor/screens/GameCamera.java +++ b/core/src/ch/asynk/creepingarmor/screens/GameCamera.java @@ -28,8 +28,9 @@ public class GameCamera extends OrthographicCamera private int hudCorrection; private int hudLeft; private int hudBottom; + private boolean fixedHud; - public GameCamera(float virtualWidth, float virtualHeight, float zoomOut, float zoomIn, int hudCorrection) + public GameCamera(float virtualWidth, float virtualHeight, float zoomOut, float zoomIn, int hudCorrection, boolean fixedHud) { super(virtualWidth, virtualHeight); this.zoomOut = zoomOut; @@ -42,6 +43,7 @@ public class GameCamera extends OrthographicCamera this.hudMatrix = new Matrix4(); this.hudInvProjMatrix = new Matrix4(); this.hudCorrection = hudCorrection; + this.fixedHud = fixedHud; } public void updateViewport(int screenWidth, int screenHeight) @@ -73,8 +75,15 @@ public class GameCamera extends OrthographicCamera hud.y = (hud.x * viewportHeight / viewportWidth); } - hud.width = (window.width - (2 * hud.x)); - hud.height = (window.height - (2 * hud.y)); + if (fixedHud) { + hud.x = 0; + hud.y = 0; + hud.width = screenWidth; + hud.height = screenHeight; + } else { + hud.width = (window.width - (2 * hud.x)); + hud.height = (window.height - (2 * hud.y)); + } widthFactor = (viewportWidth / screenWidth); heightFactor = (viewportHeight / screenHeight); @@ -84,10 +93,19 @@ public class GameCamera extends OrthographicCamera hudMatrix.setToOrtho2D(hud.x, hud.y, hud.width, hud.height); hudInvProjMatrix.set(hudMatrix); Matrix4.inv(hudInvProjMatrix.val); + } + public void applyMapViewport() + { Gdx.gl.glViewport((int)window.x, (int)window.y, (int)window.width, (int)window.height); } + public void applyHudViewport() + { + if (fixedHud) + Gdx.gl.glViewport(0, 0, screenWidth, screenHeight); + } + public Matrix4 getHudMatrix() { return hudMatrix; @@ -182,11 +200,12 @@ public class GameCamera extends OrthographicCamera public void unprojectHud(float x, float y, Vector3 v) { - x = x - window.x; + Rectangle r = (fixedHud ? hud : window); + x = x - r.x; y = Gdx.graphics.getHeight() - y - 1; - y = y - window.y; - v.x = (2 * x) / window.width - 1; - v.y = (2 * y) / window.height - 1; + y = y - r.y; + v.x = (2 * x) / r.width - 1; + v.y = (2 * y) / r.height - 1; v.z = 2 * v.z - 1; v.prj(hudInvProjMatrix); } diff --git a/core/src/ch/asynk/creepingarmor/screens/GameScreen.java b/core/src/ch/asynk/creepingarmor/screens/GameScreen.java index 52b5139..5c3dcfc 100644 --- a/core/src/ch/asynk/creepingarmor/screens/GameScreen.java +++ b/core/src/ch/asynk/creepingarmor/screens/GameScreen.java @@ -23,6 +23,7 @@ public class GameScreen implements Screen { private static boolean DEBUG = false; + private static final boolean FIXED_HUD = true; private static final float INPUT_DELAY = 0.1f; private static final float ZOOM_IN_MAX = 0.3f; private static final float ZOOM_OUT_MAX = 1f; @@ -54,7 +55,7 @@ public class GameScreen implements Screen this.batch = new SpriteBatch(); this.ctrl = new Ctrl(game, game.config.battle); - this.cam = new GameCamera(ctrl.map.getWidth(), ctrl.map.getHeight(), ZOOM_OUT_MAX, ZOOM_IN_MAX, game.hudCorrection); + this.cam = new GameCamera(ctrl.map.getWidth(), ctrl.map.getHeight(), ZOOM_OUT_MAX, ZOOM_IN_MAX, game.hudCorrection, FIXED_HUD); if (DEBUG) this.debugShapes = new ShapeRenderer(); @@ -144,6 +145,7 @@ public class GameScreen implements Screen Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // cam.update(); + cam.applyMapViewport(); batch.setProjectionMatrix(cam.combined); batch.begin(); ctrl.map.draw(batch); @@ -159,6 +161,7 @@ public class GameScreen implements Screen debugShapes.end(); } + cam.applyHudViewport(); batch.setProjectionMatrix(cam.getHudMatrix()); batch.begin(); ctrl.hud.draw(batch, DEBUG); |