This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.

in Engine by (29 points)

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"

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.

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.

1 Answer

0 votes
Best answer

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"
by (3,505 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.