ImageFrames

Inherits: Resource < Reference < Object

A container for Image frames.

Description

A class used to load and arrange a sequence of image frames. Allows to load animated image formats externally (only GIF is supported currently). Each frame can specify a delay for animated images. The data can then be used to generate an AnimatedTexture or a SpriteFrames via script.

Methods

void add_frame ( Image image, float delay=-1 )
void clear ( )
Rect2 get_bounding_rect ( ) const
int get_frame_count ( ) const
float get_frame_delay ( int index ) const
Image get_frame_image ( int index ) const
Error load ( String path, int max_frames=0 )
Error load_gif_from_buffer ( PoolByteArray data, int max_frames=0 )
void remove_frame ( int index )
Error save_gif ( String filepath, int color_count=256 )
void set_frame_delay ( int index, float delay )
void set_frame_image ( int index, Image image )

Method Descriptions

Adds a new frame.


  • void clear ( )

Removes all frames.


  • Rect2 get_bounding_rect ( ) const

Returns the bounding rectangle which encloses all added images starting from position Vector2(0, 0).


  • int get_frame_count ( ) const

Returns the total number of frames.


  • float get_frame_delay ( int index ) const

Returns the delay of frame idx.


  • Image get_frame_image ( int index ) const

Returns the Image of frame idx.


Loads the data from a file located at path. Recognizes the following file extensions: gif. The max_frames parameter limits the number of frames which can be loaded.


Loads the data from a PoolByteArray GIF buffer. The max_frames parameter limits the number of frames which can be loaded.


  • void remove_frame ( int index )

Removes the frame idx.


Saves a GIF file using frames added with add_frame. If there are multiple images, creates an animated GIF, taking into account individual frame delays. If there’s only one image, GIF is written as a static image.

The color_count parameter specifies the number of colors in GIF color map. The number of colors are rounded to nearest power of two, and the maximum number of colors is 256.

Frames can have different sizes. Dimensions of the first frame is taken as the base canvas size.

Note that GIF animation timing is measured in hundredths of a second, and delay values below 0.02 may fallback to 1.0 second when rendered on screen, which depends on application displaying such a GIF.

This method depends on ImageIndexed used to generate image palette required to write GIF files. By default, indexed images will be created from all images in ImageFrames. If ImageFrames already contains ImageIndexed, then you must ensure that ImageIndexed has color palette already generated with ImageIndexed.generate_palette prior to calling this method.

Saving animated image as transparent is also supported, given all frames are provided in Image.FORMAT_RGBA8 format, but note that transparency is not consistently supported across GIF decoders.


  • void set_frame_delay ( int index, float delay )

Sets the delay in seconds of frame idx.


  • void set_frame_image ( int index, Image image )

Sets the Image of frame idx.