1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 16:14:22 +00:00
hella-farm/behaviours/sprite_left_right.gd

24 lines
532 B
GDScript3
Raw Normal View History

2024-04-15 03:43:07 +00:00
extends Sprite2D
class_name SpriteLeftRight
@export var left_texture: Texture2D
@export var right_texture: Texture2D
var last_discrim: float = 0
2024-04-15 03:43:07 +00:00
func handle_move(movement: Vector2):
var discrim = movement.x
if discrim == 0:
discrim = last_discrim
if discrim > 0:
2024-04-15 03:43:07 +00:00
texture = right_texture
2024-04-30 03:17:57 +00:00
for child in get_children():
child.scale.x = -abs(child.scale.x)
last_discrim = discrim
elif discrim < 0:
2024-04-15 03:43:07 +00:00
texture = left_texture
2024-04-30 03:17:57 +00:00
for child in get_children():
child.scale.x = abs(child.scale.x)
last_discrim = discrim