walking and idle animations

master
chimchooree 1 year ago
parent 83faf15858
commit 50a478fd5c

@ -1,4 +1,4 @@
[gd_scene load_steps=30 format=2]
[gd_scene load_steps=31 format=2]
[ext_resource path="res://res/level/neighbor.png" type="Texture" id=1]
[ext_resource path="res://res/character/girl.png" type="Texture" id=2]
@ -108,26 +108,36 @@ flags = 4
atlas = ExtResource( 2 )
region = Rect2( 0, 200, 33, 50 )
[sub_resource type="AtlasTexture" id=23]
flags = 4
atlas = ExtResource( 2 )
region = Rect2( 0, 0, 33, 50 )
[sub_resource type="SpriteFrames" id=21]
animations = [ {
"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ) ],
"loop": true,
"name": "WalkRight",
"speed": 5.0
"speed": 10.0
}, {
"frames": [ SubResource( 6 ), SubResource( 7 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ) ],
"loop": true,
"name": "WalkLeft",
"speed": 5.0
"speed": 10.0
}, {
"frames": [ SubResource( 11 ), SubResource( 12 ), SubResource( 13 ), SubResource( 14 ), SubResource( 15 ) ],
"loop": true,
"name": "WalkUp",
"speed": 5.0
"speed": 10.0
}, {
"frames": [ SubResource( 16 ), SubResource( 17 ), SubResource( 18 ), SubResource( 19 ), SubResource( 20 ) ],
"loop": true,
"name": "WalkDown",
"speed": 10.0
}, {
"frames": [ SubResource( 23 ) ],
"loop": true,
"name": "Idle",
"speed": 5.0
} ]
@ -156,7 +166,7 @@ script = ExtResource( 5 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="World/Enter/Girl/KinematicBody2D"]
frames = SubResource( 21 )
animation = "WalkDown"
animation = "Idle"
[node name="CollisionShape2D" type="CollisionShape2D" parent="World/Enter/Girl/KinematicBody2D"]
position = Vector2( 1, -2 )

@ -41,15 +41,19 @@ func movement_key_pressed(direction):
if direction == 1: # right
velocity_sum.x = 0
velocity_sum.x += 1
get_user().animate("WalkRight")
elif direction == 2: # left
velocity_sum.x = 0
velocity_sum.x -= 1
get_user().animate("WalkLeft")
elif direction == 3: # up
velocity_sum.y = 0
velocity_sum.y -= 1
get_user().animate("WalkUp")
elif direction == 4: # down
velocity_sum.y = 0
velocity_sum.y += 1
get_user().animate("WalkDown")
# Velocity cannot be faster with more vectors
get_user().set_internal_velocity(velocity_sum)
@ -58,9 +62,10 @@ func movement_key_released(direction):
velocity_sum.x = 0
elif direction == 3 or direction == 4: # up/down
velocity_sum.y = 0
get_user().animate("Idle")
get_user().set_internal_velocity(velocity_sum)
# Physics Process
func _physics_process(delta):
func _physics_process(_delta):
## Keyboard Movement
get_input()

@ -3,6 +3,9 @@ extends Node
## Nodes
func get_body_node():
return $KinematicBody2D
func get_sprite_node():
return $KinematicBody2D/AnimatedSprite
## Parameters
func set_gpos(new_pos):
return get_body_node().set_gpos(new_pos)
@ -10,3 +13,7 @@ func get_gpos():
return get_body_node().get_gpos()
func set_internal_velocity(new_vel):
get_body_node().set_internal_velocity(new_vel)
## Logic
func animate(animation):
get_sprite_node().play(animation)

@ -26,7 +26,7 @@ func track_pos(new_pos):
positions.pop_front()
# Handle
func handle(character):
func handle(_character):
return
# var current_pos = character.get_gpos()
# track_pos(current_pos)

Loading…
Cancel
Save