Simple sprite animation playing too fast

Godot Version



Hello everyone, good afternoon!

I’m facing a rather - I believe - trivial issue trying to animate a simple AnimationSprite2D node. The problem - again, I believe - is the “Attack” animation of the player being very short, just 3 frames (the 3rd one, by the way, coinciding with the initial frame on the “Idle” animation that follows), and playing very quickly using just the code below:

@onready var sprite = $AnimatedSprite2D"Attack")

Looking up the forum I saw the user “Weranjana De Silva” seemed to have a very similar issue on his/her post: The "Shoot" animation plays way too fast - #3 by weranjanadesilva, but still no success even after a similar implementation.

To keep this short - it’s my first post around here - I tried meddling with the FPS from the animations, tried also through “AnimationPlayer” node animations, but still didn’t get it to play a little slower.

I’d appreciate any insights on this, let me know if any additional info is needed as well.
Glad to be here :slight_smile:

Note that each animation has its own FPS setting. Maybe you set it while you had the wrong animation selected? You can play the animation in the editor and should see a difference there already. Alternatively, you can modify the speed_scale property of the AnimatedSprite2D node, which will affect all animations equally. Similarly, you can also pass a second argument to play to set a custom speed.

If you tried all of this to no success, it’s probably best to upload an example project that shows the issue.

Hi @njamster,

Thanks for jumping in.
Yes, already tried all your suggestions really… In the editor, the Attack animation plays fine and with the correct speed, but when previewing the problem shows.

Here is the project file. Never really used github, so please tell me if there’s something missing/wrong;

Thanks in advance;

You have to upload the entire directory the project.godot file is in. The file itself only holds the ProjectSettings. It’s not enough to reproduce your problem.

Good morning @njamster,

Uploaded all the root files to the directory now - except the .godot that’s ignored.

Thanks for pointing it out. :beers:

It may not look like it, but your animation is playing at correct speed. The actual issue is that you’re switching away to another animation in _update_animation right away. Put these lines at the beginning of the function and see for yourself:

func update_animations(direction):
    if sprite.animation == "Attack" and sprite.is_playing():
    # ...

PS: Your script contains a standalone expression (you should see a warning about this), i.e. a line without any effect. Instead of this:

func _on_area_2d_area_entered(_area):
    is_Hit = true   # one equal sign!

you do this:

func _on_area_2d_area_entered(_area):
    is_Hit == true   # two equal signs!

Yes, you’re right. I sarted a short timer after this section

func _process(delta):
	if Input.is_action_just_pressed("attack") && !is_attacking:"Attack")

so the next animation doesn’t play until its timeout() and indeed the attack animation plays just right… I’m thinking about going down this route, using timers for every animation, but I’m afraid it get way too complicated down the line.

As for the = and ==, thanks for pointing it out. I fully understand the concept but when coding sometimes I have to stop and think before typing those…

Note that AnimatedSprite2D has animation_finished and animation_looped signals you can connect to! No need to reinvent the wheel. :wink:

Yeah, all part of the learning process I suppose :slight_smile:
Thanks for the directions @njamster!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.