0 votes

Hello, need a little help. I'm asking two things here.

  1. How do i flip the sprites/animations? I don't seem to get set_flip_h(true) working when i refer to the AnimationPlayer.

  2. How do i make my animations work in the game? I have a run cycle only showing a single frame, the first frame.

    if Input.is_action_pressed("ui_right"):
    motion.x = WALK
    sprite_node.play("RUN")
    
asked Feb 2, 2018 in Engine by KND2501 (102 points)
edited Mar 13, 2018 by KND2501

3 Answers

0 votes

1/ AnimationPlayer doesn't have a flip_h property. You'll need to set that on the Sprite itself using either flip_h or set_flip_h().

2/ When you use play(anim) it starts the animation from the beginning. In your code you're repeatedly calling play() on the AnimationPlayer every frame that the right key is being held down, do it's constantly restarting the animation. You want to play the animation only when the key is first pressed, and stop it (or play a different animation) when you release it. An easy way to do this is to use Input.is_action_just_pressed(action) which will only be true for the first frame of the key being pressed. eg:

 if Input.is_action_just_pressed("ui_right"):
    sprite_node.play("RUN")
answered Feb 2, 2018 by literalcitrus (498 points)

I've been sick so i have been occupied with my bed for a bit.

Anyway i actually got the h-flip to work on my KinematicBody2D.

    if Input.is_action_pressed("ui_right"):
    motion.x = WALK
    $"P1 Sprites/AnimationPlayer".play("RUN")
    $"P1 Sprites".flip_h = false

Now my character moves and faces the direction its moving to. But yeah, still no animation since its just showing the first frame continously. So if i am going to use...

if Input.is_action_just_pressed("ui_right"): 
$"P1 Sprites/AnimationPlayer".play("RUN")

... where am i going to put these lines?

–1 vote

This is what i was looking for.

$Sprite.flip_h = true
answered Mar 13, 2018 by KND2501 (102 points)
0 votes

A bit late butyou can in a sense rotate the AnimationPlayer by making it a child of a node the flip the node using its scale property on the x axis scale.x = -1 or 1 respectively.

answered Oct 5, 2019 by Chevon (28 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.