Loading...
Loading...
Use this skill when rendering thousands of lightweight sprites in PixiJS v8. Covers ParticleContainer with Particle instances, addParticle/removeParticle, particleChildren array, dynamicProperties (vertex, position, rotation, uvs, color), boundsArea, roundPixels, update. Triggers on: ParticleContainer, Particle, IParticle, addParticle, particleChildren, dynamicProperties, boundsArea, particle effects, constructor options, ParticleContainerOptions, ParticleOptions.
npx skill4agent add pixijs/pixijs-skills pixijs-scene-particle-containerParticleContainerContainerpixijs-scene-core-conceptsParticleContainerParticleparticleChildrenaddParticleaddChildParticleContainerContainerconst 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);pixijs-scene-core-conceptspixijs-scene-spritepixijs-assetspixijs-performancepixijs-scene-containerContainerpositionscaletintlabelfilterszIndexskills/pixijs-scene-core-concepts/references/constructor-options.mdchildrenparticles| Option | Type | Default | Description |
|---|---|---|---|
| | | Shared base texture for all particles. If omitted, the container falls back to the texture of the first particle added; every particle must share the same base texture source. |
| | | Initial array of |
| | | Flags for which particle attributes re-upload to the GPU every frame. Only |
| | | Rounds particle positions to the nearest pixel. Produces crisper rendering for pixel-art styles at the cost of smooth sub-pixel motion. |
| | default particle shader | Replaces the default particle shader. The custom shader must declare |
boundsAreaContainerParticleContainer(0, 0, 0, 0)boundsAreacontainsPointParticleContainerContainerOptions| Option | Type | Default | Description |
|---|---|---|---|
| | — | Required. Texture used to render this particle. All particles in the same |
| | | X position in the container's local space. |
| | | Y position in the container's local space. |
| | | Horizontal scale factor. |
| | | Vertical scale factor. |
| | | Horizontal anchor in 0–1 range; |
| | | Vertical anchor in 0–1 range; |
| | | Rotation in radians. |
| | | Tint color as hex number or CSS color string. Combined with |
| | | Transparency (0–1). Values outside the range are clamped. Combined with |
Texturenew Particle(texture)new Particle({ texture })Particle.defaultOptionsconst particle = new Particle({
texture,
x: 100,
y: 200,
scaleX: 0.5,
scaleY: 0.5,
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.PI / 4,
tint: 0xff0000,
alpha: 0.8,
});
container.addParticle(particle);ParticlexyscaleXscaleYanchorXanchorYrotationcolortexturetintalphacolorTexturenew Particle(texture)Particle.defaultOptionsParticle.defaultOptions = {
...Particle.defaultOptions,
anchorX: 0.5,
anchorY: 0.5,
};const particles = Array.from(
{ length: 10000 },
() =>
new Particle({
texture,
x: Math.random() * 800,
y: Math.random() * 600,
}),
);
const container = new ParticleContainer({
texture,
boundsArea: new Rectangle(0, 0, 800, 600),
particles,
});particlesaddParticleconst container = new ParticleContainer({
dynamicProperties: {
rotation: true,
},
});dynamicPropertiesParticleContainer.defaultOptions.dynamicProperties{ vertex: false, position: true, rotation: false, uvs: false, color: false }vertexpositionrotationuvscolorcontainer.update()container.particleChildren.forEach((p) => {
p.tint = 0x00ff00;
});
container.update();// Bulk add
const batch = [];
for (let i = 0; i < 5000; i++) {
batch.push(
new Particle({ texture, x: Math.random() * 800, y: Math.random() * 600 }),
);
}
container.particleChildren.push(...batch);
container.update();
// Bulk remove
container.particleChildren.length = 0;
container.update();addParticleaddParticleAtremoveParticleremoveParticleAtremoveParticlesupdate()textureParticleContainerOptionsconst container = new ParticleContainer({ texture });shaderShaderaPositionaUVaColordynamicPropertiesconst container = new ParticleContainer({ texture, shader: myCustomShader });ParticleContainershaderParticleContainerContainerParticleContainer| Standard Container method | ParticleContainer equivalent |
|---|---|
| |
| |
| |
| |
| |
| Access |
| Not available |
| Not available |
const container = new ParticleContainer();
const sprite = new Sprite(texture);
container.addChild(sprite);const container = new ParticleContainer();
const particle = new Particle(texture);
container.addParticle(particle);ParticleContainerSpriteaddChildParticleIParticleaddParticleParticleContainerSpriteconst container = new ParticleContainer();
// bounds is always (0, 0, 0, 0) — culling and hit testing failconst container = new ParticleContainer({
boundsArea: new Rectangle(0, 0, 800, 600),
});ParticleContainer(0, 0, 0, 0)boundsAreacontainsPointboundsAreacontainer.addParticle(new Particle(texture));
console.log(container.children.length); // 0container.addParticle(new Particle(texture));
console.log(container.particleChildren.length); // 1particleChildrenchildrenContainer.childrenParticleContainerparticleChildren*ParticleParticleContainerParticleContainerContainerconst world = new Container();
world.addChild(backgroundSprite, particleContainer, uiLayer);