I create a2D android game with LibGDX
and I use an orthographic camera to move around the world.
In order to move the camera, the player should touch and drag the screen. So if you touch the screen and drag rightwards, the camera should move left. So it should be just like moving the section of a zoomed picture in the gallery. I hope you are following me.
This is the code:
public class CameraTestMain extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
OrthographicCamera camera;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
camera = new OrthographicCamera(1280, 720);
camera.update();
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
handleInput();
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
public void handleInput() {
// That is my problem
}
}
I don't know what to write in the handleInput()
method. I know that there is an interface called InputProcessor
with the method touchDragged(int x, int y, int pointer)
where you can handle Touch Drag but I have no idea how to use it.
Thanks for your ideas and your help.