From d010f9a17f6fb1ebbce3cad4a691783d6bbbed86 Mon Sep 17 00:00:00 2001 From: Just Dzhi Date: Sun, 1 Oct 2023 18:10:09 +0400 Subject: [PATCH] Player idle animand flip --- src/models/player/Player.tscn | 3 +-- src/models/player/player.gd | 14 +++++++++----- src/models/player/sprites/player_spriteframes.tres | 11 ++++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/models/player/Player.tscn b/src/models/player/Player.tscn index d68ab9c..c39d192 100644 --- a/src/models/player/Player.tscn +++ b/src/models/player/Player.tscn @@ -72,8 +72,7 @@ script = ExtResource( 2 ) [node name="Sprite" type="AnimatedSprite" parent="."] material = ExtResource( 3 ) frames = ExtResource( 1 ) -animation = "run" -frame = 2 +animation = "idle" playing = true centered = false diff --git a/src/models/player/player.gd b/src/models/player/player.gd index 788a7d2..faf4ab6 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -37,11 +37,6 @@ func draw_dashed_line(from, to, color, width, dash_length = 3, cap_end = false, if cap_end: draw_line(segment_start, to, color, width, antialiased) -func _process(_delta): - if Input.is_action_just_pressed("shoot"): - _shoot() - update() - func get_input(): var input_direction = Input.get_vector("left", "right", "up", "down") velocity = input_direction * speed @@ -76,6 +71,15 @@ func _draw(): var dist2enemy = position.distance_to(target.global_position) draw_dashed_line(Vector2(12, 8), target.global_position - self.global_position + Vector2(8, 7), Color("ffde00"), 1) +func _process(_delta): + $Sprite.play("idle") if velocity == Vector2.ZERO else $Sprite.play("run") + if abs(velocity.x) > 10: + $Sprite.flip_h = true if velocity.x < 0 else false + + if Input.is_action_just_pressed("shoot"): + _shoot() + update() + func _physics_process(delta): get_input() diff --git a/src/models/player/sprites/player_spriteframes.tres b/src/models/player/sprites/player_spriteframes.tres index 7214716..05d506d 100644 --- a/src/models/player/sprites/player_spriteframes.tres +++ b/src/models/player/sprites/player_spriteframes.tres @@ -1,7 +1,11 @@ -[gd_resource type="SpriteFrames" load_steps=8 format=2] +[gd_resource type="SpriteFrames" load_steps=9 format=2] [ext_resource path="res://src/models/player/sprites/run.png" type="Texture" id=1] +[sub_resource type="AtlasTexture" id=7] +atlas = ExtResource( 1 ) +region = Rect2( 0, 0, 22, 25 ) + [sub_resource type="AtlasTexture" id=1] atlas = ExtResource( 1 ) region = Rect2( 0, 0, 22, 25 ) @@ -28,6 +32,11 @@ region = Rect2( 110, 0, 22, 25 ) [resource] animations = [ { +"frames": [ SubResource( 7 ) ], +"loop": true, +"name": "idle", +"speed": 0.0 +}, { "frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ) ], "loop": true, "name": "run",