|
|
|
|
Reply From: |
kidscancode |
You’re getting this error because $AnimatedSprite
, aka get_node("AnimatedSprite")
, can’t work before the node is in the tree and ready. Set the animation in _ready()
when you know the child node will exist and be ready.
Rule of thumb: You can’t access nodes before _ready()
.
Secondly, set_animation()
doesn’t return anything, so why are you trying to do it in an array?
(Fair warning, I’m rather new ) Hm, so are you saying I don’t need the var “textures” at all? Also thanks for clarifying the error for me. I used set_animation simply because I didn’t know how to work any other alternative. I thought I could substitute an icon’s path with set_animation, and instead of having to make a separate player scene for every single character I planned on adding to the shop, I could make the respective animated sprites in the original player script, and just have it load the “new character”
Spafnar | 2020-12-30 07:15
I actually wonder where you got set_animation()
from at all. If you look in the Inspector for the AnimatedSprite, you’ll see that animation
is a property. That means it’s like a variable. To change or use it, you just use its name.
$AnimatedSprite.animation = "up"
It’s really not that clear what you’re trying to do, but here’s how an AnimatedSprite works:
In the frames
property is a SpriteFrames resource. This resource contains the animations that the sprite can play. Each animation has a name, so you can choose the one you want by setting animation
.
Inside the SpriteFrames object are all the individual images that make up the animations. Since it can contain multiple animations, you shouldn’t need to be loading anything - you can set them all up to begin with. You can create a new SpriteFrames library by choosing “New SpriteFrames” when you click the frames
property in the Inspector.
The official tutorial uses an AnimatedSprite, and is a good example of how to work with one: Your first game — Godot Engine (3.2) documentation in English
You can reference all of this here:
AnimatedSprite — Godot Engine (3.2) documentation in English
SpriteFrames — Godot Engine (3.2) documentation in English
kidscancode | 2020-12-30 18:28
And if there were two animations, each with their own set of frames, it would then be $AnimatedSprite.animation = “animation1, animation2” ? I guess I’m confused on how to change a character’s entire animation set for all directions and assign it to the respective button in shop. I already drew the spriteframes and arranged them correctly, as well as put them in the Player.
Spafnar | 2021-01-01 09:42
An AnimatedSprite can only play one animation at a time, so no, you can’t set animation
like that.
To change the set of animations, you’d need to make separate SpriteFrames resources and set them with the frames
property.
kidscancode | 2021-01-01 18:54