Stopping an AnimatedTexture's animation (by code)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Modley

Is there any way to stop an AnimatedTexture’s animation BY CODE? Basically by setting the FPS to 0?

:bust_in_silhouette: Reply From: jgodfrey

An AnimatedTexture has a pause property. Is that what you’re looking for?

That’s really great! Thanks! …I just don’t know how to get a Resource inside another Resource’s properties :stuck_out_tongue:

Modley | 2022-12-15 18:31

So, an AnimatedTexture can be used anywhere a standard Texture resource can be used. Most (all?) objects that accept a Texture have a texture property that provides access to the underlying texture. So, looking at a simple Sprite object, you can do something like this:

var anim = AnimatedTexture.new() # create and define a new AnimatedTexture
anim.frames = 2
anim.set_frame_texture(0, texture)
anim.set_frame_texture(1, texture2)
$Sprite.texture = anim # assign the animated texture as the Sprite's Texture

… and, then later, to pause the animation…

$Sprite.texture.pause = true

jgodfrey | 2022-12-15 19:10