Player idle animand flip
parent
a1668dc8f2
commit
d010f9a17f
|
@ -72,8 +72,7 @@ script = ExtResource( 2 )
|
||||||
[node name="Sprite" type="AnimatedSprite" parent="."]
|
[node name="Sprite" type="AnimatedSprite" parent="."]
|
||||||
material = ExtResource( 3 )
|
material = ExtResource( 3 )
|
||||||
frames = ExtResource( 1 )
|
frames = ExtResource( 1 )
|
||||||
animation = "run"
|
animation = "idle"
|
||||||
frame = 2
|
|
||||||
playing = true
|
playing = true
|
||||||
centered = false
|
centered = false
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,6 @@ func draw_dashed_line(from, to, color, width, dash_length = 3, cap_end = false,
|
||||||
if cap_end:
|
if cap_end:
|
||||||
draw_line(segment_start, to, color, width, antialiased)
|
draw_line(segment_start, to, color, width, antialiased)
|
||||||
|
|
||||||
func _process(_delta):
|
|
||||||
if Input.is_action_just_pressed("shoot"):
|
|
||||||
_shoot()
|
|
||||||
update()
|
|
||||||
|
|
||||||
func get_input():
|
func get_input():
|
||||||
var input_direction = Input.get_vector("left", "right", "up", "down")
|
var input_direction = Input.get_vector("left", "right", "up", "down")
|
||||||
velocity = input_direction * speed
|
velocity = input_direction * speed
|
||||||
|
@ -76,6 +71,15 @@ func _draw():
|
||||||
var dist2enemy = position.distance_to(target.global_position)
|
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)
|
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):
|
func _physics_process(delta):
|
||||||
get_input()
|
get_input()
|
||||||
|
|
||||||
|
|
|
@ -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]
|
[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]
|
[sub_resource type="AtlasTexture" id=1]
|
||||||
atlas = ExtResource( 1 )
|
atlas = ExtResource( 1 )
|
||||||
region = Rect2( 0, 0, 22, 25 )
|
region = Rect2( 0, 0, 22, 25 )
|
||||||
|
@ -28,6 +32,11 @@ region = Rect2( 110, 0, 22, 25 )
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
animations = [ {
|
animations = [ {
|
||||||
|
"frames": [ SubResource( 7 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "idle",
|
||||||
|
"speed": 0.0
|
||||||
|
}, {
|
||||||
"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ) ],
|
"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "run",
|
"name": "run",
|
||||||
|
|
Loading…
Reference in New Issue