name: pixijs-scene-container description: "Use for PixiJS v8 Container: addChild/removeChild, transforms, sortableChildren/zIndex, boundsArea, culling, render groups, masks, coordinate conversion, destroy." license: MIT
Use this for grouping display objects, managing children, transforms, bounds, z-order, culling, and lifecycle.
Fast Path
import { Container, Sprite } from 'pixi.js';
const group = new Container({ label: 'enemy-layer', sortableChildren: true });
group.addChild(sprite);
group.position.set(100, 80);
app.stage.addChild(group);
Rules
Containeris the scene-graph node that can have children;Sprite,Graphics,Text, andMeshare leaves.- Use
addChild,addChildAt,removeChild,removeChildren,swapChildren, andsetChildIndexfor hierarchy changes. - Use
zIndexonly when the parent hassortableChildren = true; otherwise child order is insertion order. - Use
position,scale,rotation,pivot,skew, andalphaon containers instead of redrawing children. - Use
toGlobal/toLocalfor coordinate conversion. - Set
boundsAreaorcullAreawhen automatic bounds are too expensive. - Use
destroy({ children: true })only when children should be destroyed too.
Deep Reads
- Full Container API examples: references/details.md
- Core scene references:
pixijs-scene-core-concepts/references/constructor-options.md,container-hierarchy.md,transforms.md,render-groups.md,masking.md - Performance:
pixijs-performance
Common Fixes
- Adding children to a leaf: wrap the leaf in a
Container. zIndexhas no effect: enablesortableChildrenon the parent.- Wrong pointer math: convert from global to local before hit testing.