+1 vote

I want to swap out the SpriteFrames loaded onto my AnimatedSprite to indicate where the player's direction is. I made 4 different SpriteFrames saved as *.tres and on the source folder. How do I swap them out on runtime using GDScript?

in Engine by (142 points)

1 Answer

+3 votes
Best answer

In GDScript, if you want to change the SpriteFrames resource of an AnimatedSprite, you can do like this:

var frames = preload("path/to/your_sprite_frames.tres")

However I think you don't need to make 4 SpriteFrames resources for each direction. I had a look at the editor, and realized it works like AnimationPlayer. You can have multiple sprite sequences in a single SpriteFrames, like this:

enter image description here

With this other technique you can play any of these by name in GDScript:

by (28,880 points)
selected by

Oh wow, how did I not think of that. Thanks! I even have a walk and run set and never bothered to think "hmm.. maybe I can add the 4 directions here too"

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.