I am trying to render some entities in random positions on the screen. The spawning positions are okay however when I move the player entity (which the camera is focused on) and pass the middle of the screen (then the camera starts moving) the sprites of the other entities also move with me, which I do not want.

I tried giving them postions in the world and not in the screen using cam.unproject(position); which converts psotions relative to the screen into positions relative to the game world, but that did not work either.

They are rendered the same way all other sprites are rendered in libgdx

This is the code where I initialize the entities:

Texture zombie = new Texture("zombie.png");
    float x, y;
    for (int i = 0; i < enemy_amout; i++) {
        x = rm.nextFloat() * (mapWidth * 8f- zombie.getWidth());
        y = rm.nextFloat() * (mapHeight * 8f - zombie.getHeight());
        Vector3 position = new Vector3(x, y, 0);
        enemies[i] = new Entity(zombie, position.x, position.y, 1);

This is what the game looks like when I start it

And this is what it looks like after I moved the player character to the right. As you can see they moved alongside the camera but I want them to remain on their original positions.

  • Would you mind to show us how you are rendering the Player character – Sebastien Servouze May 16 at 9:31
  • So I fixed this problem by adding batch.setPrejwctionMatrix(cam.combined); but now all the sprites are rendering with enormous dimensions even though internally they are stillt 55x66px – Grual May 18 at 15:43
  • Hmmm, would you mind show us Player / Ennemies initialization AND drawing ? – Sebastien Servouze May 21 at 7:25
  • Enemy initialization is already in the post and this is the player initialization "player = new Entity(new Texture("character.png"), 0, 0, 3);". The Entity class has a sprite object in int that is initialized with the texture in the CConstructor and is drawn by simply calling the draw method of sprite – Grual May 25 at 5:44

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.