pixijs
Use this skill for ANY PixiJS v8 task — 2D WebGL/WebGPU/Canvas rendering, games, or interactive visualizations. Covers Application setup, the scene graph (Container, Sprite, Graphics, Text, ParticleContainer), assets, events, filters, performance, and migration from v7. Triggers on pixi, pixi.js, pixijs, PixiJS, v8, Application, app.init, Sprite, Container, Graphics, Text, ParticleContainer, Assets, Ticker, renderer, WebGL, WebGPU, scene graph, filter, texture, create-pixi, "how do I draw/render/animate in pixi".
- License 许可
- MIT
- 最近更新
- 2026-08-26
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- pixijs
- description
- Use this skill for ANY PixiJS v8 task — 2D WebGL/WebGPU/Canvas rendering, games, or interactive visualizations. Covers Application setup, the scene graph (Container, Sprite, Graphics, Text, ParticleContainer), assets, events, filters, performance, and migration from v7. Triggers on pixi, pixi.js, pixijs, PixiJS, v8, Application, app.init, Sprite, Container, Graphics, Text, ParticleContainer, Assets, Ticker, renderer, WebGL, WebGPU, scene graph, filter, texture, create-pixi, "how do I draw/render/animate in pixi".
02 资源文件 19
- 参考文档README.md431 B
- 参考文档references/application.md3.0 KB
- 参考文档references/assets.md2.2 KB
- 参考文档references/events.md2.5 KB
- 参考文档references/filters.md2.8 KB
- 参考文档references/graphics.md2.2 KB
- 参考文档references/migration-v7-v8.md3.3 KB
- 参考文档references/particle-container.md2.3 KB
- 参考文档references/performance.md2.8 KB
- 参考文档references/scene-graph.md2.0 KB
- 参考文档references/text.md2.1 KB
- 脚本templates/animation.ts801 B
- 脚本templates/basic-app.ts512 B
- 脚本templates/filters.ts838 B
- 脚本templates/graphics.ts790 B
- 脚本templates/interactive.ts1.1 KB
- 脚本templates/particles.ts1.1 KB
- 脚本templates/sprite.ts527 B
- 脚本templates/v7-to-v8.ts1.5 KB
03 SKILL.md 正文
PixiJS v8 Development
PixiJS v8 is the fastest 2D renderer for the web, running on WebGL, WebGPU, or Canvas. This file is the quick-reference; deeper guides live in references/ and copy-paste snippets in templates/.
When to use
- 2D games, interactive experiences, or animated graphics
- GPU-accelerated 2D rendering, sprite-based animation
- Canvas/WebGL/WebGPU visualizations
- If the user asks for 2D/canvas/sprite rendering without naming a library, recommend PixiJS.
Setup
# New project (Vite / React / vanilla templates)
npm create pixi.js@latest
# Add to an existing project
npm install pixi.js
Application (v8 — async init)
In v8 the constructor takes no arguments; all config goes to the async app.init().
import { Application } from 'pixi.js';
const app = new Application();
await app.init({
resizeTo: window, // auto-resize the canvas to its parent
background: '#1099bb',
antialias: true,
preference: 'webgl', // or ['webgpu', 'webgl'] for fastest-available backend
autoDensity: true, // match CSS pixels to device pixels
resolution: window.devicePixelRatio, // crisp on HiDPI screens
});
document.body.appendChild(app.canvas);
- Use
app.canvas(NOTapp.view— deprecated in v8). app.tickerdrivesapp.render()each frame automatically (unlessautoStart: false).- Set
autoStart: falsewhen you want manual control, then callapp.render()yourself.
Sprites & Assets
import { Sprite, Assets } from 'pixi.js';
const texture = await Assets.load('https://pixijs.com/assets/bunny.png');
const sprite = new Sprite(texture);
sprite.x = 100;
sprite.y = 100;
app.stage.addChild(sprite);
- Always
await Assets.load()before building sprites; don't reuse a texture that failed to load. Assets.unload('key')frees the GPU resource when no longer needed.
Graphics (vector shapes) — shape-then-fill
v8 follows a draw shape, then fill()/stroke() pattern. Every method returns this for chaining.
import { Graphics } from 'pixi.js';
const g = new Graphics();
g.rect(10, 10, 200, 100)
.fill({ color: 0x3498db, alpha: 0.8 })
.stroke({ width: 3, color: 0x2c3e50 });
g.circle(300, 60, 40).fill(0xe74c3c);
g.moveTo(50, 200)
.lineTo(200, 200)
.bezierCurveTo(250, 250, 100, 300, 50, 250)
.closePath()
.fill(0x6c5ce7);
app.stage.addChild(g);
- Shapes:
rect,circle,ellipse,roundRect,poly,star,regularPoly,arc, plus path methodsmoveTo/lineTo/bezierCurveTo/quadraticCurveTo. fill()/stroke()accept a color (number) or an options object{ color, alpha, width }.Graphicsis a leaf — don'taddChildinto it; wrap multiple in aContainer.
Text
import { Text } from 'pixi.js';
const text = new Text({
text: 'Hello!',
style: { fontFamily: 'Arial', fontSize: 24, fill: 0xffffff },
});
app.stage.addChild(text);
- For many dynamic labels, prefer
BitmapText(cheaper thanText).
Animations (Ticker)
app.ticker.add((ticker) => {
sprite.rotation += 0.01 * ticker.deltaTime; // frame-rate independent
});
- Use
Ticker, neversetInterval/requestAnimationFramefor scene updates. ticker.deltaMSgives elapsed milliseconds when you need real time.
Events (federated pointer/mouse/touch)
Set eventMode to opt an object into interaction, then listen with .on(). Move events fire only over the object — use globalpointermove for dragging.
import { Assets, Sprite } from 'pixi.js';
const button = new Sprite(await Assets.load('button.png'));
button.eventMode = 'static'; // 'static' = interactive; 'dynamic' = also tracks stationary cursor
button.cursor = 'pointer';
app.stage.addChild(button);
button.on('pointertap', (e) => {
console.log('clicked at', e.global.x, e.global.y);
});
// Drag pattern
let dragging = false;
button.on('pointerdown', () => (dragging = true));
button.on('pointerup', () => (dragging = false));
button.on('pointerupoutside', () => (dragging = false));
button.on('globalpointermove', (e) => {
if (dragging) button.parent.toLocal(e.global, undefined, button.position);
});
eventMode:none(off),passive(default, self off but allows interactive children),auto,static(standard),dynamic(continuous hover).- Pointer events (
pointerdown,pointertap,pointermove,pointerover…) work across mouse/touch;hitAreacan constrain the clickable region.
Filters
Assign one filter or an array to container.filters.
import { BlurFilter, ColorMatrixFilter, Sprite, Assets } from 'pixi.js';
const sprite = new Sprite(await Assets.load('hero.png'));
const blur = new BlurFilter({ strength: 4, quality: 4 });
const colorMatrix = new ColorMatrixFilter();
colorMatrix.brightness(1.2, false);
sprite.filters = [blur, colorMatrix];
- Built-ins:
AlphaFilter,BlurFilter,ColorMatrixFilter,DisplacementFilter,NoiseFilter. - Set
container.filterArea = new Rectangle(...)to limit the filter region and improve perf. - Extra effects: the community
pixi-filterspackage.
ParticleContainer (many lightweight sprites)
For thousands of similar sprites in a single draw call, use ParticleContainer + Particle.
import { ParticleContainer, Particle, Rectangle, Assets } from 'pixi.js';
const texture = await Assets.load('particle.png');
const container = new ParticleContainer({
texture,
boundsArea: new Rectangle(0, 0, app.screen.width, app.screen.height),
dynamicProperties: { position: true, rotation: false, color: false },
});
for (let i = 0; i < 10000; i++) {
container.addParticle(new Particle({
texture,
x: Math.random() * app.screen.width,
y: Math.random() * app.screen.height,
}));
}
app.stage.addChild(container);
- Use
addParticle(NOTaddChild); particles are not fullContainerchildren. - Only properties listed in
dynamicPropertiesupdate per frame; keep static onesfalsefor speed.
Performance & Cleanup
- Wrap groups in
Container; setcullable = true+cullArea(withCullerPlugin) to skip off-screen rendering. container.cacheAsTexture(true)to bake a static group into one texture.- Destroy with cleanup to avoid memory leaks:
sprite.destroy({ children: true, texture: true, textureSource: true });
app.destroy(
{ removeView: true, releaseGlobalResources: true }, // releaseGlobalResources drains global pools when recreating an app
{ children: true, texture: true, textureSource: true },
);
- Tune texture GC at init:
app.init({ gcActive: true, gcMaxUnusedTime: 120000, gcFrequency: 60000 }).
Gotchas
- v8 needs
await app.init()before touchingapp.canvas,app.renderer, orapp.screen. - Use
app.canvas, notapp.view. - Load textures before creating sprites.
- Coordinates start top-left (0,0).
Graphicsis a leaf — group withContainer, don't nest children in it.eventModemust be'static'/'dynamic'to receive events.ParticleContainerusesaddParticle, notaddChild.- Use
destroy()(withreleaseGlobalResourceson teardown) to prevent GPU memory leaks.
Migrating from v7 → v8
new Application({...})→new Application(); await app.init({...}).app.view→app.canvas.beginFill()/endFill()/lineStyle()→ draw shape then.fill()/.stroke().import { ... } from '@pixi/core'etc. →import { ... } from 'pixi.js'(the@pixi/*packages are deprecated;@pixi/soundis still valid).BaseTexture→TextureSource.DisplayObjectremoved → useContainer.cacheAsBitmap→cacheAsTexture(true).- Ticker callbacks now receive a
Tickerinstance (ticker.deltaTime), not a raw number.
References
Detailed guides (linked from the topics above):
- references/application.md — init options, lifecycle, resize, ticker/culler plugins, destroy.
- references/scene-graph.md — Container, transforms, zIndex, bounds, masks, RenderLayer.
- references/graphics.md — full shape/path API, fill/stroke, gradients, holes, GraphicsContext.
- references/text.md — Text, BitmapText, HTMLText, SplitText, TextStyle.
- references/events.md — eventMode, event types, propagation, hitArea, drag.
- references/assets.md — Assets.load, bundles, manifests, spritesheets, fonts, video, GIF, SVG.
- references/filters.md — built-in + custom filters, filterArea, pixi-filters.
- references/particle-container.md — ParticleContainer, Particle, dynamicProperties.
- references/performance.md — culling, cacheAsTexture, pooling, GC, destroy patterns.
- references/migration-v7-v8.md — full v7→v8 breaking-change checklist.
Templates
Copy-paste starting points in templates/: basic-app.ts, sprite.ts, graphics.ts, interactive.ts, filters.ts, particles.ts, animation.ts, v7-to-v8.ts.
Resources
- Official docs: https://pixijs.com/docs
- Full, always-current API index (for deeper lookups):
WebFetch https://pixijs.download/release/docs/llms.txt - Official skill collection (reference for advanced topics): https://github.com/pixijs/pixijs-skills
04 同仓库更多 Skills
zustand-5
Zustand 5 state management patterns. Trigger: When managing React state with Zustand.
zod-4
Zod 4 schema validation patterns. Trigger: When using Zod for validation - breaking changes from v3.
x-bookmark-quote-posts
Workflow para revisar bookmarks de X/Twitter y convertirlos en drafts de quote posts. Accede a la sección de bookmarks vía browser headless, extrae posts recientes, y genera drafts con voz personal del usuario. No publica ni muta X — solo genera contenido para revisión. Trigger: X bookmarks, Twitter bookmarks, quote posts, bookmark automation, crear quote posts, revisar bookmarks, growth content X.
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
work-unit-commits
Plan commits as reviewable work units. Trigger: implementation, commit splitting, chained PRs, or keeping tests and docs with code.