GIFTexture

Inherits: Texture2D < Texture < Resource < RefCounted < Object

A self-contained animated Texture2D that decodes, stores, and plays a GIF.

Description

GIFTexture is the single resource for GIF content: it owns the decoded frame data and its playback state. Assign it to Sprite2D, Sprite3D, TextureRect, materials, or shader uniforms like any other Texture2D. Importing a .gif file produces a GIFTexture. Each scene instance gets its own copy (Resource.resource_local_to_scene is enabled by default), so playback state never leaks between instances; use "Make Unique" when two nodes in the same scene must play independently. Looping honors netscape_loop_count while loop is true.

Properties

bool

autoplay_on_load

true

bool

bake_compress

false

BakeStorage

bake_storage

1

Array[Image]

baked_frames

[]

Vector2i

canvas_size

Vector2i(0, 0)

int

current_frame

0

DisplayMode

display_mode

0

bool

dither

true

bool

loop

true

int

netscape_loop_count

0

bool

play

false

Array[Image]

source_frames

[]

float

speed_scale

1.0

Methods

void

add_source_frame(image: Image, delay_cs: int = 10, disposal: Disposal = 0, position: Vector2i = Vector2i(0, 0))

Error

bake_frames()

GIFTexture

from_sprite_frames(frames: SpriteFrames, animation_name: StringName = &"default") static

Texture2D

get_active_texture(frame: int)

Image

get_baked_image(frame: int) const

int

get_frame_count() const

int

get_frame_delay(frame: int) const

float

get_frame_delay_sec(frame: int) const

Disposal

get_frame_disposal(frame: int) const

bool

get_frame_has_transparency(frame: int) const

Vector2i

get_frame_position(frame: int) const

int

get_frame_transparent_color(frame: int) const

Image

get_source_image(frame: int) const

Error

load_from_buffer(buffer: PackedByteArray)

Error

load_from_path(path: String)

PackedByteArray

save_to_buffer() const

Error

save_to_path(path: String) const

SpriteFrames

to_sprite_frames(animation_name: StringName = &"default")

int

wrap_frame(frame: int) const


Signals

frames_changed() 🔗

Emitted when the frame data changes (load, add_source_frame, reimport).


rebaked() 🔗

Emitted after bake_frames() composites new baked frames.


Enumerations

enum DisplayMode: 🔗

DisplayMode DISPLAY_SOURCE = 0

There is currently no description for this enum. Please help us by contributing one!

DisplayMode DISPLAY_BAKED = 1

There is currently no description for this enum. Please help us by contributing one!


enum BakeStorage: 🔗

BakeStorage BAKE_STORE = 0

There is currently no description for this enum. Please help us by contributing one!

BakeStorage BAKE_GENERATE_ON_LOAD = 1

There is currently no description for this enum. Please help us by contributing one!


enum Disposal: 🔗

Disposal DISPOSAL_NONE = 0

There is currently no description for this enum. Please help us by contributing one!

Disposal DISPOSAL_DO_NOT_DISPOSE = 1

There is currently no description for this enum. Please help us by contributing one!

Disposal DISPOSAL_RESTORE_BACKGROUND = 2

There is currently no description for this enum. Please help us by contributing one!

Disposal DISPOSAL_RESTORE_PREVIOUS = 3

There is currently no description for this enum. Please help us by contributing one!


Property Descriptions

bool autoplay_on_load = true 🔗

  • void set_autoplay_on_load(value: bool)

  • bool get_autoplay_on_load()

If true, playback starts automatically when the texture is loaded or instanced. Disable this to keep the first frame until play is set.


bool bake_compress = false 🔗

  • void set_bake_compress(value: bool)

  • bool get_bake_compress()

Compress baked frame images.


BakeStorage bake_storage = 1 🔗

Whether baked frames are stored in the resource or regenerated on load.


Array[Image] baked_frames = [] 🔗

There is currently no description for this property. Please help us by contributing one!


Vector2i canvas_size = Vector2i(0, 0) 🔗

Logical canvas size of the GIF.


int current_frame = 0 🔗

  • void set_current_frame(value: int)

  • int get_current_frame()

Visible frame index.


DisplayMode display_mode = 0 🔗

Whether rendering uses raw source frames or composited baked frames.


bool dither = true 🔗

  • void set_dither(value: bool)

  • bool get_dither()

Dithering used when encoding GIFs.


bool loop = true 🔗

  • void set_loop(value: bool)

  • bool get_loop()

If true, playback repeats according to netscape_loop_count.


int netscape_loop_count = 0 🔗

  • void set_netscape_loop_count(value: int)

  • int get_netscape_loop_count()

Netscape loop count from the file: 0 loops forever, N plays N times.


bool play = false 🔗

  • void set_play(value: bool)

  • bool get_play()

If true, the texture advances frames. Non-looping playback automatically clears this when the animation finishes; setting it again restarts from frame 0.


Array[Image] source_frames = [] 🔗

There is currently no description for this property. Please help us by contributing one!


float speed_scale = 1.0 🔗

  • void set_speed_scale(value: float)

  • float get_speed_scale()

Playback speed. Negative values play in reverse.


Method Descriptions

void add_source_frame(image: Image, delay_cs: int = 10, disposal: Disposal = 0, position: Vector2i = Vector2i(0, 0)) 🔗

Appends a raw frame with delay (centiseconds), disposal method, and canvas offset.


Error bake_frames() 🔗

Composites source frames (disposals, offsets, transparency) into full-canvas baked frames.


GIFTexture from_sprite_frames(frames: SpriteFrames, animation_name: StringName = &"default") static 🔗

Creates a GIFTexture from a SpriteFrames animation.


Texture2D get_active_texture(frame: int) 🔗

Returns the composited texture for a frame index.


Image get_baked_image(frame: int) const 🔗

Returns the baked full-canvas image of a frame.


int get_frame_count() const 🔗

Returns the number of frames.


int get_frame_delay(frame: int) const 🔗

There is currently no description for this method. Please help us by contributing one!


float get_frame_delay_sec(frame: int) const 🔗

There is currently no description for this method. Please help us by contributing one!


Disposal get_frame_disposal(frame: int) const 🔗

There is currently no description for this method. Please help us by contributing one!


bool get_frame_has_transparency(frame: int) const 🔗

There is currently no description for this method. Please help us by contributing one!


Vector2i get_frame_position(frame: int) const 🔗

There is currently no description for this method. Please help us by contributing one!


int get_frame_transparent_color(frame: int) const 🔗

There is currently no description for this method. Please help us by contributing one!


Image get_source_image(frame: int) const 🔗

Returns the raw source image of a frame.


Error load_from_buffer(buffer: PackedByteArray) 🔗

Decodes GIF data into this texture, replacing all frames.


Error load_from_path(path: String) 🔗

Decodes a GIF file into this texture, replacing all frames.


PackedByteArray save_to_buffer() const 🔗

Encodes the current frames as GIF data.


Error save_to_path(path: String) const 🔗

Encodes the current frames as a GIF file.


SpriteFrames to_sprite_frames(animation_name: StringName = &"default") 🔗

Converts the frames to a SpriteFrames animation.


int wrap_frame(frame: int) const 🔗

Wraps an arbitrary frame index into the valid range.