Making an animation start when a button is pressed

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

My nodes are like this:

  • Kinematicbody2D
    Animated sprite (Which runs all the time)
    CollisionShape2D
    Camera2D

I want the animation to start when i hit D or A, so that the run animations will start when it moves, and stops when i go idle.

:bust_in_silhouette: Reply From: Becbunzen

You can use this function, that is there by default in the templates:

func _process(delta):

It will run every frame, there you can check if the button is pressed and use/start/stop the correct animation.

Have you done any relevant tutorials? Perhaps this one could be useful to you? https://github.com/GDQuest/godot-beginner-2d-platformer