Player idle animand flip

main
Just Dzhi 2023-10-01 18:10:09 +04:00
parent a1668dc8f2
commit d010f9a17f
3 changed files with 20 additions and 8 deletions

View File

@ -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

View File

@ -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()

View File

@ -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",