Created
February 19, 2015 05:28
-
-
Save xaguzman/b0a644ea7ee5d3e25a12 to your computer and use it in GitHub Desktop.
Libgdx - Orthographic Camera Pan & Zoom Input processor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PanZoomCameraInput extends InputAdapter { | |
OrthographicCamera cam; | |
Vector3 lastTouch, tmp; | |
public PanZoomCameraInput(OrthographicCamera cam){ | |
this.cam = cam; | |
lastTouch = new Vector3(); | |
tmp = new Vector3(); | |
} | |
@Override | |
public boolean touchDown(int screenX, int screenY, int pointer, int button) { | |
lastTouch.set(screenX, screenY, 0); | |
return false; | |
} | |
@Override | |
public boolean touchDragged(int screenX, int screenY, int pointer) { | |
tmp.set(screenX, screenY, 0).sub(lastTouch).scl(-1, 1, 0).scl(cam.zoom); | |
cam.translate(tmp); | |
lastTouch.set(screenX, screenY, 0); | |
return false; | |
} | |
@Override | |
public boolean scrolled(int amount) { | |
cam.zoom *= amount > 0 ? 1.05f : 0.95f; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment