0

I am trying to render some sprites and I need the line batch.setProjectionMatrix(cam.combined); in order for the sprites to move independently from the camera, however when I add this line the sprites suddenly turn abnormally large, but without it they are just normal. I have the suspicion that it changes the world dimensions or something like that, because the the boundaries I set for the player sprite are also expanded, just like the size of the sprites, but the background (a tiledmap rendered with a OrthogonalTiledMapRenderer) stays the same.

This is the normal rendering as it should be: https://ibb.co/m4T2GT

This is the rendering i get when using setProjectionMatrix: https://ibb.co/j0EL38

(I used an external site for the pictures because for some reason I could not add them here)

This is my render function.

player.draw(..);

and

e.draw(..);

just call the draw function of the Sprite class.

public void render() {
    handleInput();
    renderer.setView(cam);
    renderer.render();

    batch.setProjectionMatrix(cam.combined);
    batch.begin();
    player.draw(batch);

    for (Entity e: enemies) e.draw(batch);

    batch.end();
}
Grual
  • 73
  • 6
  • batch.setProjectionMatrix(cam.combined); isn't to move sprites or sth. See: https://stackoverflow.com/a/33703806/7717409 – icarumbas May 25 '18 at 16:51
  • well it fixed my original problem that's what I was saying but it created a new one – Grual May 25 '18 at 19:38

1 Answers1

0

You can use the float: cam.zoom to change how large everything appears. Change it in setup or just after you initialise the camera object, then it should remain at that zoom.

If that doesn't work, you might need to set the map rendering to the camera's projection matrix as well.

TheChubbyPanda
  • 1,721
  • 2
  • 16
  • 37