Animated Sprite (individual images) vs Sprite (spritesheet)

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

It seems when i have an animated sprite i can just use for example:
"if Input.is_action_pressed(“ui_left):

But when its an AnimationPlayer in a regular sprite it only works if its “is_action_just_pressed” wich is not always optimal as in a platformer game for exemple.

I understand that it doenst work in animationPlayer because it tries to start it over every frame, but that makes the coding a lot more complicated.

Is there a way to just use “is_action_pressed” with spritesheets?

:bust_in_silhouette: Reply From: Socrates

You can do something like:

if Input.is_action_pressed("ui_left"):
         if $AnimationPlayer.current_animation != "run":

There is also a somewhat better way to do this in the Platformer2D demo in the demo projects. This is the link if you don’t have them: GitHub - godotengine/godot-demo-projects: Demonstration and Template Projects

Thanks! That did it.

Diogoamorim27 | 2018-03-13 00:06

:bust_in_silhouette: Reply From: jobax

You could set the animation to loop, and then stop it when you let go of the key?