summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-12 16:24:10 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-12 16:24:10 +0200
commitbd5d36de7d5fd8d8bf8b27dbe64cc79010f1f4bb (patch)
treee5dad523319075699d28c940ee07d31dd537cb6a /core/src/ch/asynk
parenta73e8da681577e8b28a176dae366fd708b80ed73 (diff)
downloadRustAndDust-bd5d36de7d5fd8d8bf8b27dbe64cc79010f1f4bb.zip
RustAndDust-bd5d36de7d5fd8d8bf8b27dbe64cc79010f1f4bb.tar.gz
move camera position clamp from render() to input processor
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index 9f86bcb..a460519 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -69,6 +69,7 @@ public class GameScreen extends AbstractScreen
{
cam.zoom += ((initialDistance - distance) / 300.f);
cam.zoom = MathUtils.clamp(cam.zoom, 0.4f, maxZoom);
+ clampCameraPos();
return true;
}
}));
@@ -79,6 +80,7 @@ public class GameScreen extends AbstractScreen
cam.translate((touchX - x) * cam.zoom, (y - touchY) * cam.zoom, 0);
touchX = x;
touchY = y;
+ clampCameraPos();
return true;
}
@Override
@@ -95,6 +97,7 @@ public class GameScreen extends AbstractScreen
{
cam.zoom += amount / ZOOM_FACTOR;
cam.zoom = MathUtils.clamp(cam.zoom, 0.4f, maxZoom);
+ clampCameraPos();
return true;
}
});
@@ -102,17 +105,20 @@ public class GameScreen extends AbstractScreen
return multiplexer;
}
+ private void clampCameraPos()
+ {
+ 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));
+ }
+
@Override
public void render(float delta)
{
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- // handleInput();
- float width = cam.viewportWidth * cam.zoom / 2f;
- float height = cam.viewportHeight * cam.zoom / 2f;
- cam.position.x = MathUtils.clamp(cam.position.x, width, (mapSprite.getWidth() - width));
- cam.position.y = MathUtils.clamp(cam.position.y, height, (mapSprite.getHeight() - height));
cam.update();
batch.setProjectionMatrix(cam.combined);