Libgdx Actions => gradually move the actor from point A to point B

I want to gradually revive my Actor. I added this action to move the Actor from point A to point B.

addAction(Actions.sequence(Actions.moveBy(1, 1), Actions.moveTo(posX, posY)));

Also tried this (moveTo after 10 seconds):

addAction(Actions.moveTo(posX, posY, 10)));

But the actor is moving too fast. What's wrong?

+5
source share
2 answers

Second form:

addAction(Actions.moveTo(posX, posY, 10)));

should move your actor to posX, posY for 10 seconds.

The first form will move the actor 1-step to x and y, and after that move the actor immediately to posX, posY. Actions.sequenceperforms these actions one by one, they do not change each other.

( ) act() ? , Actor , , , .

+10

, , "Libgdx Move to Point". .

, :

Vector2 , :

protected Vector2 v2Position;
protected Vector2 v2Velocity;

. :

public void setVelocity (float toX, float toY) {

// The .set() is setting the distance from the starting position to end position
v2Velocity.set(toX - v2Position.x, toY - v2Position.y);
v2Velocity.nor(); // Normalizes the value to be used

v2Velocity.x *= speed;  // Set speed of the object
v2Velocity.y *= speed;
}

Velocity ,

@Override public void update() {
    v2Position.add (v2Velocity);    // Update position
}
+4

All Articles