Learning in Programming
Learning in Programming
Learned that you can make an animated sprite without making a children called “animated
sprite” just make a new child to the sprite called “animation ” and it accomplishes the same
thing.
extends KinematicBody2D
func _ready():
pass
func _physics_process(delta):
motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
motion.y = MAXFALLSPEED
if facing_right == true:
$Sprite.scale.x = 1
else:
$Sprite.scale.x = -1
if Input.is_action_pressed("right"):
motion.x += ACCELERATION
facing_right = true
$AnimationPlayer.play("run")
elif Input.is_action_pressed("left"):
motion.x -= ACCELERATION
facing_right = false
$AnimationPlayer.play("run")
else:
motion.x = lerp(motion.x,0,0.2)
$AnimationPlayer.play("idle")
if is_on_floor():
if Input.is_action_just_pressed("jump"):
motion.y = -JUMP
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("jump")
elif motion.y > 0:
$AnimationPlayer.play("falling")
___________________________________________
extends KinematicBody2D
func _ready():
pass
func _physics_process(delta):
motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
motion.y = MAXFALLSPEED
if facing_right == true:
$Sprite.scale.x = 1
else:
$Sprite.scale.x = -1
if Input.is_action_pressed("right"):
motion.x += ACCELERATION
facing_right = true
$AnimationPlayer.play("run")
elif Input.is_action_pressed("left"):
motion.x -= ACCELERATION
facing_right = false
$AnimationPlayer.play("run")
else:
motion.x = lerp(motion.x,0,0.2)
$AnimationPlayer.play("idle")
if is_on_floor():
can_jump = true
if Input.is_action_just_pressed("jump"):
motion.y = -JUMP
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("jump")
elif motion.y > 0:
$AnimationPlayer.play("falling")
Snake Game