Loading...
Loading...
Use this skill when displaying animated GIFs in PixiJS v8. Covers the pixi.js/gif side-effect import, Assets.load returning a GifSource, GifSprite playback (play/stop/currentFrame/animationSpeed), autoPlay/loop options, onComplete/onLoop/onFrameChange callbacks, GifSource sharing, clone, destroy. Triggers on: GifSprite, GifSource, pixi.js/gif, animationSpeed, currentFrame, autoPlay, onComplete, onFrameChange, constructor options, GifSpriteOptions.
npx skill4agent add pixijs/pixijs-skills pixijs-scene-gifGifSpriteAssets.load('animation.gif')GifSourceTextureGifSpriteimport 'pixi.js/gif'pixijs-scene-core-conceptsGifSpriteSpriteGifSpriteContainerimport "pixi.js/gif";
import { GifSprite } from "pixi.js/gif";
const source = await Assets.load("animation.gif");
const gif = new GifSprite({
source,
autoPlay: true,
loop: true,
animationSpeed: 1,
});
gif.anchor.set(0.5);
gif.x = app.screen.width / 2;
gif.y = app.screen.height / 2;
app.stage.addChild(gif);[!NOTE] GIFs decode every frame into a separate canvas texture. For performance-critical animations with many frames, prefer a spritesheet with— it uses a single atlas texture and batches better on the GPU.AnimatedSprite
pixijs-scene-core-conceptspixijs-scene-spriteAnimatedSpritepixijs-assetsAssets.loadpixijs-tickerpixijs-performanceGifSpriteOptionsOmit<SpriteOptions, 'texture'>texturesource.textures[0]SpriteanchorscaletintroundPixelsContainerpositionscaletintlabelfilterszIndexskills/pixijs-scene-core-concepts/references/constructor-options.mdGifSpriteOptions| Option | Type | Default | Description |
|---|---|---|---|
| | — | Required. The parsed GIF data returned by |
| | | Start playback immediately on construction. If |
| | | Repeat the animation on reaching the last frame. When |
| | | Multiplier on the GIF's native frame timing. |
| | | Connect playback to |
| | | Fallback frame rate for GIFs that do not specify per-frame delays. |
| | | Called when a non-looping animation reaches the last frame. |
| | | Called each time a looping animation wraps around. |
| | | Called every time the displayed frame index changes. |
| | | Deprecated since 8.13.0 — pass |
GifSourcenew GifSprite(source)new GifSprite({ source })import "pixi.js/gif";
import { Assets } from "pixi.js";
import { GifSprite } from "pixi.js/gif";
const source = await Assets.load("animation.gif");
const gif = new GifSprite({ source });pixi.js/gifextensions.add(GifAsset).gifAssets.loadGifSpriteGifSourcepixi.js/gifpixi.jspixi.js/gifimport 'pixi.js/gif'const gif = new GifSprite({ source });
gif.play();
gif.stop();
gif.currentFrame = 5;
gif.animationSpeed = 2;
gif.animationSpeed = 0.5;
gif.playing; // read-only
gif.progress; // 0-1 playback position
gif.totalFrames; // number of frames
gif.duration; // total duration in msautoPlay: trueloop: trueanimationSpeedcurrentFrameconst source = await Assets.load({
src: "animation.gif",
data: {
fps: 12,
scaleMode: "nearest",
resolution: 2,
},
});
const fromDataUri = await Assets.load("data:image/gif;base64,R0lGODlh...");dataGifSource.fromfpsscaleModeresolution.gifdata:image/gifconst gif = new GifSprite({
source,
loop: false,
onComplete: () => console.log("animation finished"),
onLoop: () => console.log("loop completed"),
onFrameChange: (frame) => console.log("now on frame", frame),
});onCompleteonLooponFrameChangeconst gif = new GifSprite({ source, autoUpdate: false });
app.ticker.add((ticker) => {
gif.update(ticker);
});autoUpdate: falseTicker.sharedgif.update(ticker)Tickerconst source = await Assets.load("animation.gif");
const gif1 = new GifSprite({ source, autoPlay: true });
const gif2 = new GifSprite({ source, autoPlay: false });
const gif3 = gif1.clone();
gif3.animationSpeed = 0.5;GifSourceGifSpriteclone()import { Assets } from "pixi.js";
const gif = await Assets.load("animation.gif");import "pixi.js/gif";
import { Assets } from "pixi.js";
const source = await Assets.load("animation.gif");.gifconst texture = await Assets.load("animation.gif");
const sprite = new Sprite(texture);const source = await Assets.load("animation.gif");
const gif = new GifSprite({ source });Assets.loadGifSourceGifSpritesource.textures[0]gif.destroy();
// GifSource and frame textures remain in memorygif.destroy(true);
// or
await Assets.unload("animation.gif");gif.destroy()destroy(false)GifSourcetrueAssets.unloadGifSpriteSpriteallowChildren = falseContainerconst group = new Container();
group.addChild(gif, label);