Please, help me with my issue. I need to move an Actor to dynamic coordinates of another Actor. If I use MoveToAction, the Actor moves to the given GetX() and GetY() coordinates of another Actor, but does not follow it as it moves.
This simple code move Actor to old coordinates of another Actor. I want the game element to follow the moving player.:
game_element = new GameContainer();
stage.addActor(game_element);
game_element.addAction(Actions.moveTo(player.getX(), player.getY(), 2));
But if I move the player at the moment when the game element moves to him, then he arrives at the old coordinates, and does not follow him. How can this be implemented in LibGDX?
Depending on the details of what you're after this can be achieved by creating your own
Action.This example will try to get to the target
Actorat a constant speed, and theActionis disabled when the followed reaches the target (but this can easily be changed by changing the behaviour of theactmethod)In the image below the T is the target and the F is the follower and the T has two sequenced actions moving it to two corners, and the F has only the
MoveToActorAction.