summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-12 14:42:21 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-12 14:42:21 +0200
commit0b45d496943a108c6971abc4f7d2a89fc1b636f3 (patch)
treeb3ffa22f3370c05ab3b3c054b250779036d71fce /core/src/ch/asynk/tankontank
parent0d579c6daad93b01e222f6298daf2d1da6d9760c (diff)
downloadRustAndDust-0b45d496943a108c6971abc4f7d2a89fc1b636f3.zip
RustAndDust-0b45d496943a108c6971abc4f7d2a89fc1b636f3.tar.gz
use InputMultiplexer to handle Gestures, apply zoom to touchDragged()
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index ceddf48..9f86bcb 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -4,6 +4,10 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.InputAdapter;
+import com.badlogic.gdx.InputMultiplexer;
+import com.badlogic.gdx.input.GestureDetector;
+import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
+
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
@@ -53,11 +57,26 @@ public class GameScreen extends AbstractScreen
viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), cam);
- Gdx.input.setInputProcessor(new InputAdapter() {
+ Gdx.input.setInputProcessor(getMultiplexer());
+ }
+
+ private InputMultiplexer getMultiplexer()
+ {
+ final InputMultiplexer multiplexer = new InputMultiplexer();
+ multiplexer.addProcessor(new GestureDetector(new GestureAdapter() {
+ @Override
+ public boolean zoom(float initialDistance, float distance)
+ {
+ cam.zoom += ((initialDistance - distance) / 300.f);
+ cam.zoom = MathUtils.clamp(cam.zoom, 0.4f, maxZoom);
+ return true;
+ }
+ }));
+ multiplexer.addProcessor(new InputAdapter() {
@Override
public boolean touchDragged(int x, int y, int pointer)
{
- cam.translate((touchX - x), - (touchY - y), 0);
+ cam.translate((touchX - x) * cam.zoom, (y - touchY) * cam.zoom, 0);
touchX = x;
touchY = y;
return true;
@@ -79,6 +98,8 @@ public class GameScreen extends AbstractScreen
return true;
}
});
+
+ return multiplexer;
}
@Override