Topic was automatically imported from the old Question2Answer platform.
Asked By
KND2501
Hello, need a little help. I’m asking two things here.
How do i flip the sprites/animations? I don’t seem to get set_flip_h(true) working when i refer to the AnimationPlayer.
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")
You can always simply get a sprite with a different run for right and left and then bind those animations to the keybind. But if you really want to work like this then the option that worked for me is:
With the ACCELERATION being my build up speed variable, Sprite the name of my sprite node, and AnimationPlayer the name of my AnimationPlayer node. I looked around but never noticed this option anywhere so I thought that I had to comment on it. Have fun coding everyone!
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")
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")
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.