4.6 Updating Animations
This commit is contained in:
parent
d227c3e098
commit
256d057662
1 changed files with 20 additions and 0 deletions
|
|
@ -4,6 +4,8 @@ extends CharacterBody2D
|
|||
@export var speed = 300.0
|
||||
@export var jump_velocity = 400.0
|
||||
|
||||
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
|
|
@ -19,3 +21,21 @@ func _physics_process(delta: float) -> void:
|
|||
velocity.x = direction * speed
|
||||
|
||||
move_and_slide()
|
||||
play_animations(direction)
|
||||
|
||||
|
||||
func play_animations(direction: float):
|
||||
if direction != 0.0:
|
||||
animated_sprite_2d.flip_h = direction == -1.0
|
||||
|
||||
if is_on_floor():
|
||||
if direction == 0.0:
|
||||
animated_sprite_2d.play("idle")
|
||||
else:
|
||||
animated_sprite_2d.play("run")
|
||||
else:
|
||||
if velocity.y < 0:
|
||||
animated_sprite_2d.play("jump")
|
||||
else:
|
||||
animated_sprite_2d.play("fall")
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in a new issue