Pages

Tuesday, August 19, 2014

libgdx: making camera follow player

So, i had this problem. Looked everywhere and couldn't find a decent tutorial, actually any info, so here it is:

In class:
OrthographicCamera camera;
in constructor:
camera = new OrthographicCamera(Width, Height);
camera.setToOrtho(false);
in render method:
camera.position.set(player.x, player.y);
camera.update();
batch.setProjectionMatrix(camera.combined);
The last line is what was missing from all those tutorials, and the single line that makes the difference.

No comments:

Post a Comment