Search code examples
javaandroidlibgdxscene2d

Set position of an actor in LibGDX that have an action


I have a table of actors that are doing different actions (moving, jumping etc) and I want to move all of them to the left as the player moves so I tried

setPosition(getX() - 1, getY());

But it seems that this only moves the actors that are currently not busy doing MoveTo actions? I have enemies running from one side of the screen to the other with MoveTo actions, I want them to continue doing that but also move to the left at the correct speed.

I tried adding an additional action onto them

MoveByAction move = new MoveByAction();
move.setAmount(1, 0);
addAction(Actions.forever(move));

But they still seem to continue with their preset MoveTo action.


Solution

  • Short answer: you can't do it like that. I had to move actors with setPosition(getX() + 1, getY()); instead of using an action if I wanted to move them seperately.

    Also had to use a camera to "move" the entire scene at once.