I'm trying to add an action to an actor with interpolation, but the actor just teleport to the final position without the animation
I have this method in my actor class that i call after i set the final position for the animation:
private fun addMovementAsAction(){
val action = Actions.action(MoveToAction::class.java)
action.setStartPosition(initialPosition.x, initialPosition.y)
action.setPosition(finalPosition.x, finalPosition.y)
action.duration = 2f
action.interpolation = Interpolation.linear
addAction(action)
}
then, in my game class, i have a method named play() called when i click a button that calls stage.act(). When i click the button, the actor jumps to the final position without any animation. What could it be?
state.act()
must be called on every call of the render()
loop. If you only call it when a button is tapped, the whole stage will be frozen most of the time. If you're passing a value for delta
to stage.act()
when you do call it and that delta is the whole elapsed time since the last time you called it, there will be a leap through all the animations to account for all that missed time.
Other possible culprit: you said, "that i call after i set the final position for the animation". If you set actor.x
and actor.y
to the end position before adding the animation, you have teleported the actor to that position, and the MoveToAction will have nothing to do. Calling setStartPosition
on the MoveToAction before the animation has had a chance to begin accomplishes nothing, because it will take the Actor's current position as the start position automatically when the animation begins. setStartPosition()
should probably be deprecated because it can only accomplish something if you call it after the animation is already ongoing, and why would you ever want to change it after it already started?