walking and idle animations

This commit is contained in:
chimchooree
2023-09-08 10:43:27 -05:00
parent 83faf15858
commit 50a478fd5c
4 changed files with 29 additions and 7 deletions
+6 -1
View File
@@ -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()
+7
View File
@@ -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)