Animation doesn't play continuously instead it starts from frame 0.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zuckey

I’m trying to make a running animation to play at 8 directions but it seems to restart the animation at each direction change, I want it to continue from where it left. I’m using spritesheets and AnimationPlayer for animation. How can I manage this?

All your animations have the same ammount of trames? could you share your current code where you manage animation changes?

p7f | 2020-09-28 20:43

func animation_loops():
if direction <= 15 and direction >= -15:
	animation_direction = "E"
	right_arm.set_z_index(1)
	left_arm.set_z_index(-1)
	weapon1h.set_z_index(-1)
elif direction <= 60 and direction >= 15:
	animation_direction = "SE"
	right_arm.set_z_index(1)
	left_arm.set_z_index(-1)
	weapon1h.set_z_index(-1)
elif direction <= 120 and direction >= 60:
	animation_direction = "S"
	right_arm.set_z_index(0)
	left_arm.set_z_index(0)
	weapon1h.set_z_index(-1)
elif direction <= 165 and direction >= 120:
	animation_direction = "SW"
	right_arm.set_z_index(-1)
	left_arm.set_z_index(0)
	weapon1h.set_z_index(-1)
elif direction <= -15 and direction >= -60:
	animation_direction = "NE"
	right_arm.set_z_index(1)
	left_arm.set_z_index(-1)
	weapon1h.set_z_index(-1)
elif direction <= -60 and direction >= -120:
	animation_direction = "N"
	right_arm.set_z_index(0)
	left_arm.set_z_index(0)
	weapon1h.set_z_index(-1)
elif direction <= -120 and direction >= -165:
	animation_direction = "NW"
	right_arm.set_z_index(-1)
	left_arm.set_z_index(0)
	weapon1h.set_z_index(-1)
elif direction <= -165 or direction >= 165:
	animation_direction = "W"
	right_arm.set_z_index(-1)
	left_arm.set_z_index(0)
	weapon1h.set_z_index(0)

if idle_state == true:
	animation_mode = "Idle"
	anim_player.playback_speed = 1
else:
	animation_mode = "Run"
	anim_player.playback_speed = 2

animation = animation_mode + "_" + animation_direction
anim_player.play(animation)

Currently I have an idle and a running animation my idle is 8 frames long and running is 16 frames long.

Zuckey | 2020-09-28 20:48

:bust_in_silhouette: Reply From: p7f

You can use current_animation_position to look for the current animation time, and then seek after changing the animation, to put the animation in that frame… something like this:

var frame = anim_player.current_animation_position
animation = animation_mode + "_" + animation_direction
anim_player.current_animation = animation
anim_player.seek(frame)

However, this will work as long as your animations are the same length… if not, you should check before what animation are you changing to, and perhaps apply another rule, although I guess that when you change from run to idle, is ok that idle starts from zero, right?

Yes this worked, thank you so much! But there is still a problem which you mentioned where changing from run to idle there is a delay, how can i fix it?

Zuckey | 2020-09-28 21:14

If you are ok that when changing from different animation_mode (i mean, from run to idle or from idel to run) the new animation starts from 0, then you could check that if new mode is not the same as current one, just start from zero

var frame = 0
if animation_mode in animation:
    frame = anim_player.current_animation_position
animation = animation_mode + "_" + animation_direction
anim_player.current_animation = animation
anim_player.seek(frame)

p7f | 2020-09-28 21:21

Oh now I see your point, I will try that thank you!

Zuckey | 2020-09-28 21:32