Silent Program
Silent Program

Reputation: 3

New to Coding Very confused

I'm new to coding in general and I'm trying to make a sprite change texture so it has a walking animation but I can't seem to figure out how to apply a wait() or something to my code.

if Input.is_action_pressed("move_up"):
    vel.y -= 1
    facingDir = Vector2(0, -1)
    $LilBoiTexture.texture = load("res://LilBoiAssets/LilBoiBackward.png")
    
    $LilBoiTexture.texture = load("res://LilBoiAssets/LilBoiBackward2.png")

Any help is appreciated. I'm trying to change from the first texture to the second one within idk 0.5, or something ill mess with it if i can figure out what to do.

Upvotes: 0

Views: 96

Answers (1)

unlut
unlut

Reputation: 3775

There is an easier way of doing this instead of changing sprite image manually. You can use "AnimatedSprite" node as shown in the tutorial. Here are the steps:

1- Add an AnimatedSprite node to your character.
2- In properties of AnimatedSprite, Frames-> select new SpriteFrames.
3- Click SpriteFrames you just created, another menu will appear at the bottom of editor. Drag and drop your animation images to center of this menu.
4- Change animation name from default to something else (for example walkback).
5- In your code you just need to do this:

if Input.is_action_pressed("move_up"):
    $AnimatedSprite.play("walkback")
else:
    #  you can also play an idle animation if you have one
    $AnimatedSprite.stop()

Upvotes: 2

Related Questions