Loading...
Loading...
Use this skill when grouping, positioning, or transforming display objects in PixiJS v8. Covers Container constructor options (isRenderGroup, sortableChildren, boundsArea), addChild/removeChild/addChildAt/swapChildren/setChildIndex, position/scale/rotation/pivot/skew/alpha/tint, getBounds/getGlobalPosition/toLocal/toGlobal, zIndex sorting, cullable, onRender per-frame callback, destroy. Triggers on: Container, addChild, removeChild, addChildAt, swapChildren, sortableChildren, zIndex, position, scale, rotation, pivot, getBounds, toGlobal, toLocal, onRender, destroy, constructor options, ContainerOptions.
npx skill4agent add pixijs/pixijs-skills pixijs-scene-containerContainerContainerSpriteGraphicsTextMeshpixijs-scene-core-conceptsconst group = new Container({
label: "hero-group",
x: 200,
y: 150,
sortableChildren: true,
});
const body = new Sprite(await Assets.load("body.png"));
const head = new Sprite(await Assets.load("head.png"));
head.position.set(0, -40);
head.zIndex = 1;
group.addChild(body, head);
group.pivot.set(group.width / 2, group.height / 2);
group.scale.set(1.5);
app.stage.addChild(group);pixijs-scene-core-conceptspixijs-scene-spritepixijs-scene-graphicspixijs-scene-textpixijs-scene-meshpixijs-eventseventModepixijs-mathpixijs-performancecacheAsTextureconst container = new Container({
label: "world",
x: 100,
y: 50,
scale: 2,
rotation: Math.PI / 4,
alpha: 0.8,
visible: true,
tint: 0xffaa00,
blendMode: "add",
sortableChildren: true,
isRenderGroup: true,
origin: { x: 0, y: 0 },
boundsArea: new Rectangle(0, 0, 1920, 1080),
});ContainerpositionscaletintlabelfilterszIndexskills/pixijs-scene-core-concepts/references/constructor-options.mdContainerassignWithIgnorechildrenparenteffectsContainercullablecullAreamaskfilterAreaeventModehitAreaisRenderGroup: truepixijs-scene-core-concepts/references/scene-management.mdsortableChildren: truezIndexzIndexoriginObservablePointpivotoriginPointDatacontainer.origin.set(x, y)pivotoriginboundsAreagetBounds()cullablecullAreaassignWithIgnorepixijs-performanceconst parent = new Container();
const sprite = new Sprite(texture);
parent.addChild(sprite);ContainerRenderLayerSpriteGraphicsTextMeshParticleContainerDOMContainerContainerconst parent = new Container();
parent.addChild(a, b, c);
parent.addChildAt(d, 0);
parent.swapChildren(a, b);
parent.setChildIndex(c, 0);
parent.removeChild(b);
parent.removeChildAt(0);
parent.removeChildren();
parent.removeChildren(0, 2);addChildaddChildAtsetChildIndexswapChildrenremoveChildren(beginIndex?, endIndex?)addChildAtaddedchildAddedremovedchildRemovedreparentChildreparentChildAtreplaceChildconst obj = new Container();
obj.x = 100;
obj.y = 200;
obj.position.set(100, 200);
obj.scale.set(2);
obj.scale = 2;
obj.rotation = Math.PI / 4;
obj.angle = 45;
obj.pivot.set(50, 50);
obj.skew.set(0.1, 0.2);
obj.alpha = 0.5;
obj.tint = 0xff0000;
obj.visible = false;
obj.renderable = false;positionscalepivotskewObservablePointscale = 2rotationanglepivotpositionalphatintblendModevisible = falserenderable = falsegetBounds()const world = new Container({ sortableChildren: true });
const ground = new Sprite(groundTexture);
ground.zIndex = 0;
const player = new Sprite(playerTexture);
player.zIndex = 10;
const ui = new Sprite(uiTexture);
ui.zIndex = 100;
world.addChild(ground, player, ui);sortableChildrentruezIndexzIndexsortableChildrencontainer.sortChildren()zIndexRenderLayerpixijs-scene-core-concepts/references/scene-management.mdconst bounds = container.getBounds();
console.log(bounds.x, bounds.y, bounds.width, bounds.height);
const rect = container.getBounds().rectangle;
const local = new Point(10, 20);
const world = container.toGlobal(local);
const backToLocal = container.toLocal(world);
const selfPos = container.getGlobalPosition();getBounds()BoundsRectanglexywidthheight.rectangleRectanglegetBounds(skipUpdate?: boolean, bounds?: Bounds)trueBoundstoGlobal(point)toLocal(point, from?)fromgetGlobalPosition()parent.toGlobal(this._position)const sprite = new Sprite(texture);
sprite.setSize(200, 100);
const { width, height } = sprite.getSize();setSizescale.width.heightsetSizeconst parent = new Container();
parent.on("childAdded", (child, container, index) => {
console.log("added at", index, child.label);
});
parent.on("childRemoved", (child, container, index) => {
console.log("removed from", index);
});
const child = new Container();
child.on("added", (newParent) => console.log("entered", newParent.label));
child.on("removed", (oldParent) => console.log("left", oldParent.label));
child.on("visibleChanged", (visible) => console.log("visible:", visible));
child.on("destroyed", (destroyed) => console.log("gone", destroyed.label));
parent.addChild(child);| Event | Fires on | Arguments |
|---|---|---|
| the parent receiving the child | |
| the parent losing the child | |
| the child that was attached | |
| the child that was detached | |
| the destroyed container | |
| the container whose | |
EventEmitterContainerpixijs-eventsdestroyedpositionscalepivotoriginskewparentchildrendestroy()const container = new Container();
container.onRender = (renderer) => {
container.rotation += 0.01;
};
container.onRender = null;onRenderRendererupdateTransformonRender = nullconst player = world.getChildByLabel("player");
const enemies = world.getChildrenByLabel(/enemy-\d+/, true);
const bounds = hud.getLocalBounds();
oldSprite.removeFromParent();getChildByLabel(label, deep?)RegExptruegetChildrenByLabel(label, deep?, out?)getLocalBounds()getBounds()removeFromParent()thiscontainer.destroy();
container.destroy({
children: true,
texture: true,
textureSource: true,
});
console.log(container.destroyed);destroy(){ children: true }texture: truetextureSource: truecacheAsTexturecontainer.cacheAsTexture(false)const sprite = new Sprite(texture);
const overlay = new Sprite(overlayTexture);
sprite.addChild(overlay);const group = new Container();
const sprite = new Sprite(texture);
const overlay = new Sprite(overlayTexture);
group.addChild(sprite, overlay);Containerconst rect = container.getBounds();
rect.contains(x, y); // TypeError: contains is not a functionconst rect = container.getBounds().rectangle;
rect.contains(x, y);
const bounds = container.getBounds();
console.log(bounds.width, bounds.height);getBounds()BoundsxywidthheightRectangle.contains()Rectangle.rectanglecontainer.cacheAsBitmap = true;container.cacheAsTexture(true);cacheAsBitmapcacheAsTexture()cacheAsTexture(false)destroy()namelabelgetChildByLabel