0 votes

Hello trying to load a texture to a Texture text node -> Animated Texture (selected for text) frame 0 texture property (frame0/ texture) from script.
I have a 150 frames of animation and if i have to load this one by one from inspector it will be hell. I think if i can load it with script then i can write a ' for loop ' for easy load. Can you help me?

in Engine by (45 points)

1 Answer

0 votes
Best answer

Like this?

for i in range(150):
    # your texture's paths may differ!
    var texture_path = "res://texture_" + str(i) + ".png"
    $TextureRect.texture.set_frame_texture(i, load(texture_path))
by (10,469 points)
selected by

First of all thank you very much.
I tried both loading images manually and by script.
To use script you have to set frame number manually
Script doesn't do it by the way. Problem is when i use
Script in the end of loop animation stops like a quarter
Of a second. Do you have any idea why it happens.
Can it be because loading from script adds extra work on engine.

Can it be because loading from script adds extra work on engine.

No. It's called only once when the scene becomes ready. And shouldn't be any different from setting the textures manually in the editor.

To use script you have to set frame number manually

Well, yes. You can do this from script as well though:

$TextureRect.texture.frames = 8

when i use script in the end of loop animation stops like a quarter of a second

I cannot reproduce this, works fine for me. If you upload a minimal example project somewhere and provide a link here, I can take a look.

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 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 webmaster@godotengine.org with your username.