Libgdx ParallaxScrolling and TiledMaps
Posted
by
kirchhoff
on Game Development
See other posts from Game Development
or by kirchhoff
Published on 2013-07-02T19:47:18Z
Indexed on
2013/07/02
23:19 UTC
Read the original article
Hit count: 304
I implemented ParallaxScrolling for my SideScroller project, everything is working but the tiled map (the most important part!). I've been trying out everything but it doesn't work (see the code below).
I'm using ParallaxCamera from GdxTests, it's working perfectly for the background layers.
I can't explain myself properly in english, so I recorded 2 videos:
As you can see, now the platforms appear in the middle of the Y-axis.
I've got a Map class with 2 tiled maps, so I need two renderers too:
private TiledMapRenderer renderer1;
private TiledMapRenderer renderer2;
public void update(GameCamera camera) {
renderer1.setView(camera.calculateParallaxMatrix(1f, 0f), camera.position.x - camera.viewportWidth / 2,
**camera.position.y - camera.viewportHeight/2**, camera.viewportWidth, camera.viewportHeight);
renderer2.setView(camera.calculateParallaxMatrix(1f, 0f), camera.position.x - camera.viewportWidth / 2,
**camera.position.y - camera.viewportHeight/2**, camera.viewportWidth, camera.viewportHeight);
}
In bold, the code I think I should change. I've tried changing parameters, even adding hardcoded values, etc, but one of two: 1. Nothing happens. 2. Platforms disappear.
Here is some aditional code. The render method:
world.update(delta);
parallaxBackground.update(camera);
clear(0.5f, 0.7f, 1.0f, 1);
batch.setProjectionMatrix(camera.calculateParallaxMatrix(0, 0));
batch.disableBlending();
batch.begin();
batch.draw(background, -(int)background.getRegionWidth()/2, -(int)background.getRegionHeight()/2);
batch.end();
batch.enableBlending();
parallaxBackground.draw(batch, camera);
renderer.render(batch);
© Game Development or respective owner