From 2b513b8bb258ab9e1b5d4e530d59ad1f288d8147 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 15 Apr 2024 05:43:07 +0200 Subject: [PATCH] Create `SpriteLeftRight` behaviour --- behaviours/sprite_left_right.gd | 13 +++++++++++++ behaviours/sprite_left_right.tscn | 6 ++++++ 2 files changed, 19 insertions(+) create mode 100644 behaviours/sprite_left_right.gd create mode 100644 behaviours/sprite_left_right.tscn diff --git a/behaviours/sprite_left_right.gd b/behaviours/sprite_left_right.gd new file mode 100644 index 0000000..d0fd4d1 --- /dev/null +++ b/behaviours/sprite_left_right.gd @@ -0,0 +1,13 @@ +extends Sprite2D +class_name SpriteLeftRight + + +@export var left_texture: Texture2D +@export var right_texture: Texture2D + + +func handle_move(movement: Vector2): + if movement.x > 0: + texture = right_texture + else: + texture = left_texture diff --git a/behaviours/sprite_left_right.tscn b/behaviours/sprite_left_right.tscn new file mode 100644 index 0000000..7064655 --- /dev/null +++ b/behaviours/sprite_left_right.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bxbjfev0lhwws"] + +[ext_resource type="Script" path="res://behaviours/sprite_left_right.gd" id="1_mt6ma"] + +[node name="SpriteLeftRight" type="Sprite2D"] +script = ExtResource("1_mt6ma")