gif
The gif namespace decodes animated GIF files into individual pre-composited GPU textures with transparency and disposal handling resolved automatically.
Decoding GIFs
Section titled βDecoding GIFsβlocal anim = gif.decode(file_bytes: string) --> gif_t | nilDecodes raw GIF data (read via files.read). Returns nil if corrupted or invalid.
gif_t Methods & Properties
Section titled βgif_t Methods & Propertiesβ| Member | Type | Description |
|---|---|---|
width |
number |
Frame canvas width in pixels. |
height |
number |
Frame canvas height in pixels. |
duration |
number |
Total animation cycle duration in seconds. |
loop_count |
number |
Loop count (0 = loop indefinitely). |
g:frame_count() |
number |
Total frame count in the animation. |
g:frame(i) |
image_t |
Returns the texture for 1-based frame index i. |
g:delay(i) |
number |
Delay in seconds for frame i. |
g:at(time) |
image_t |
Returns the appropriate frame texture for the given timestamp in seconds. |
g:draw(pos, time, clr?) |
nil |
Composites and renders the active frame at pos directly. |
g:release() |
nil |
Deallocates all GPU textures associated with the animation. |
Example: Rendering an Animated Mascot
Section titled βExample: Rendering an Animated Mascotβlocal cat_gif = nilif files.exists("aimsense/scripts/data/cat.gif") then cat_gif = gif.decode(files.read("aimsense/scripts/data/cat.gif"))end
client.add_callback("render", function() if cat_gif then cat_gif:draw(vector(50, 50), globals.realtime) endend)
client.add_callback("unload", function() if cat_gif then cat_gif:release() endend)