Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Kayd |
Hi.
So basically I have a 2D kinematic character as the “playable” character in my game, and I want a different animation for left/right/down/up and idle. I have made all the animations as children of the “frames” resource (as labeled in the animated sprite properties).
So my question is, how do I change or “set” the animation? I’ve used the play command, which does nothing, I’ve used the set animation command which also does nothing, no matter what I do the animation doesn’t change, it just sticks with whichever animation was initially chosen as default in the properties - its as if it ignores the scripting.
func get_input():
if Input.is_action_pressed('right'):
set_animation("frames/player_move_right")
if Input.is_action_pressed('left'):
set_animation("player_move_left")
if Input.is_action_pressed('down'):
set_animation("player_move_down")
if Input.is_action_pressed('up'):
set_animation("player_move_up")
I’ve done the same thing with phsyics(delta) to try and update the animation, and I’ve used the play(“animation”) command as well, neither of which work.
If there’s a way to import a sprite sheet like every other engine that I don’t know about, please tell me.
If there’s another way to do this entirely, then that is fine as well.
Thanks for any and all feedback.
Hi,
I don’t se in the docs that set_animation
is a member function. I assume AnimatedSprite is child of KinematicBody2D. Can you try this:
$AnimatedSprite.animation = "player_move_right"
instead of what you needed? Is the AnimatedSprite
called frames
in your project or i missunderstood? in that case you should try this:
$frames.animation = "player_move_right"
p7f | 2019-01-13 23:24
Thank you so much! That cleared up a lot of stuff. I was looking for the member variable for the animation originally but couldn’t find it (I was using AnimatedSprite.animation without $ originally and I kept getting flagged, so I tried another way). This fixed it! Thanks.
Kayd | 2019-01-13 23:58
Ok! Glad to help. I’ll post it as an answer so the question doe not remain unanswered… please you may select it so others can easily find solution.
p7f | 2019-01-14 00:02