Can anyone help me using flip_h?

Godot Version

Godot 4.2.1

Question

Basically what happens is that I need to mirror a sprite horizontally, Godot didn’t highlight any errors in the script, but there must be something wrong, when I run the game and press the buttons to move the character left or right, it closes and stops responding, That’s only if I move the character, i.e. the error is in the lines where I try to mirror the sprite (25 e 27).

Script (please, ignore loopAnim function):

extends AnimatedSprite2D

@onready var PersAnim = $“.”
var SpriteToFlip = AnimatedSprite2D

func _ready():
pass

func _process(_Delta):
loopespelho()
loopAnim()

func loopAnim():

if Input.is_action_pressed("leste") or Input.is_action_pressed("oeste"):
	PersAnim.play("corrida")
else:
	PersAnim.play("padrao")

func loopespelho():

if Input.is_action_just_pressed("oeste"):
	$AnimatedSprite2D.flip_h = 1
elif Input.is_action_just_pressed("leste"):
	$AnimatedSprite2D.flip_h = 0

____________________________________________________________________________________________________.

Here’s a screenshot of Scrip (ignore loopAnim function):

image

Here’s a screenshot of the error message:

errormessagegodot

Here’s a screenshot of the online documentation about flip_h:

When you write $AnimatedSprite2D, the game tries to acces a child node with the given name. If the script is attached to the AnimatedSprite2D node, you can access its properties directly.

if Input.is_action_just_pressed("oeste"):
	flip_h = true
elif Input.is_action_just_pressed("leste"):
	flip_h = false
1 Like

That solved the problem, thank you very much!!