ExperimentalOptional ExperimentalaccessibleFlag for if the object is accessible. If true AccessibilityManager will overlay a shadow div with attributes set
Optional ExperimentalaccessibleSetting to false will prevent any children inside this container to be accessible. Defaults to true.
Optional Advanced ExperimentalaccessibleSets the aria-label attribute of the shadow div
Optional Advanced ExperimentalaccessibleSpecify the pointer-events the accessible div will use Defaults to auto.
Optional ExperimentalaccessibleSets the text content of the shadow
Optional ExperimentalaccessibleSets the title attribute of the shadow div If accessibleTitle AND accessibleHint has not been this will default to 'container [tabIndex]'
Optional Advanced ExperimentalaccessibleSpecify the type of div the accessible layer is. Screen readers treat the element differently depending on this type. Defaults to button.
ExperimentalboundsAn optional bounds area for this container. Setting this rectangle will stop the renderer from recursively measuring the bounds of each children and instead use this single boundArea.
This is great for optimisation! If for example you have a 1000 spinning particles and you know they all sit within a specific bounds, then setting it will mean the renderer will not need to measure the 1000 children to find the bounds. Instead it will just use the bounds you set.
ExperimentalcacheLegacy property for backwards compatibility with PixiJS v7 and below.
Use cacheAsTexture instead.
ExperimentalcacheCaches this container as a texture. This allows the container to be rendered as a single texture, which can improve performance for complex static containers.
If true, enables caching with default options. If false, disables caching. Can also pass options object to configure caching behavior.
// Basic caching
container.cacheAsTexture(true);
// With custom options
container.cacheAsTexture({
resolution: 2,
antialias: true,
});
// Disable caching
container.cacheAsTexture(false);
// Cache a complex UI
const ui = new Container();
// Add multiple children...
ui.cacheAsTexture(true);
ui.updateCacheTexture(); // Update if contents change
ExperimentalcharsIndividual character segments of the text.
Readonly ExperimentalchildrenThe array of children of this container. Each child must be a Container or extend from it.
The array is read-only, but its contents can be modified using Container methods.
// Access children
const firstChild = container.children[0];
const lastChild = container.children[container.children.length - 1];
Optional ExperimentalcullableControls whether this object should be culled when out of view. When true, the object will not be rendered if its bounds are outside the visible area.
Optional ExperimentalcullableControls whether children of this container can be culled. When false, skips recursive culling checks for better performance.
const container = new Container();
// Enable container culling
container.cullable = true;
// Disable child culling for performance
container.cullableChildren = false;
// Children will always render if container is visible
container.addChild(sprite1, sprite2, sprite3);
Optional ExperimentalcullCustom shape used for culling calculations instead of object bounds. Defined in local space coordinates relative to the object.
Setting this to a custom Rectangle allows you to define a specific area for culling, which can improve performance by avoiding expensive bounds calculations.
const container = new Container();
// Define custom culling boundary
container.cullArea = new Rectangle(0, 0, 800, 600);
// Reset to use object bounds
container.cullArea = null;
Optional ExperimentalcursorThe cursor style to display when the mouse pointer is hovering over the object. Accepts any valid CSS cursor value or custom cursor URL.
// Common cursor types
sprite.cursor = 'pointer'; // Hand cursor for clickable elements
sprite.cursor = 'grab'; // Grab cursor for draggable elements
sprite.cursor = 'crosshair'; // Precise cursor for selection
sprite.cursor = 'not-allowed'; // Indicate disabled state
// Direction cursors
sprite.cursor = 'n-resize'; // North resize
sprite.cursor = 'ew-resize'; // East-west resize
sprite.cursor = 'nesw-resize'; // Northeast-southwest resize
// Custom cursor with fallback
sprite.cursor = 'url("custom.png"), auto';
sprite.cursor = 'url("cursor.cur") 2 2, pointer'; // With hotspot offset
ExperimentaldestroyedWhether this object has been destroyed. If true, the object should no longer be used. After an object is destroyed, all of its functionality is disabled and references are removed.
Container#destroy For destroying objects
Optional Advanced Experimentaleffectstodo Needs docs
Optional ExperimentaleventEnable interaction events for the Container. Touch, pointer and mouse events are supported.
const sprite = new Sprite(texture);
// Enable standard interaction (like buttons)
sprite.eventMode = 'static';
sprite.on('pointerdown', () => console.log('clicked!'));
// Enable for moving objects
sprite.eventMode = 'dynamic';
sprite.on('pointermove', () => updatePosition());
// Disable all interaction
sprite.eventMode = 'none';
// Only allow child interactions
sprite.eventMode = 'passive';
Available modes:
'none': Ignores all interaction events, even on its children. Best for pure visuals.'passive': (default) Does not emit events and ignores hit testing on itself and non-interactive
children. Interactive children will still emit events.'auto': Does not emit events but is hit tested if parent is interactive. Same as interactive = false in v7.'static': Emit events and is hit tested. Same as interactive = true in v7. Best for buttons/UI.'dynamic': Like static but also receives synthetic events when pointer is idle. Best for moving objects.Performance tips:
'none' for pure visual elements'passive' for containers with some interactive children'static' for standard UI elements'dynamic' only when needed for moving/animated elementsOptional ExperimentalfilterThe area the filter is applied to. This is used as an optimization to define a specific region for filter effects instead of calculating the display object bounds each frame.
Setting this to a custom Rectangle allows you to define a specific area for filter effects, which can improve performance by avoiding expensive bounds calculations.
// Set specific filter area
container.filterArea = new Rectangle(0, 0, 100, 100);
// Optimize filter region
const screen = app.screen;
container.filterArea = new Rectangle(
screen.x,
screen.y,
screen.width,
screen.height
);
Readonly Advanced ExperimentalgroupThe group transform is a transform relative to the render group it belongs too. If this container is render group then this will be an identity matrix. other wise it will be the same as the relativeGroupTransform. Use this value when actually rendering things to the screen
Optional ExperimentalhitDefines a custom hit area for pointer interaction testing. When set, this shape will be used for hit testing instead of the container's standard bounds.
import { Rectangle, Circle, Sprite } from 'pixi.js';
// Rectangular hit area
const button = new Sprite(texture);
button.eventMode = 'static';
button.hitArea = new Rectangle(0, 0, 100, 50);
// Circular hit area
const icon = new Sprite(texture);
icon.eventMode = 'static';
icon.hitArea = new Circle(32, 32, 32);
// Custom hit area with polygon
const custom = new Sprite(texture);
custom.eventMode = 'static';
custom.hitArea = new Polygon([0,0, 100,0, 100,100, 0,100]);
// Custom hit testing logic
sprite.hitArea = {
contains(x: number, y: number) {
// Custom collision detection
return x >= 0 && x <= width && y >= 0 && y <= height;
}
};
Optional ExperimentalinteractiveWhether this object should fire UI events. This is an alias for eventMode set to 'static' or 'passive'.
Setting this to true will enable interaction events like pointerdown, click, etc.
Setting it to false will disable all interaction events on this object.
Optional ExperimentalinteractiveControls whether children of this container can receive pointer events.
Setting this to false allows PixiJS to skip hit testing on all children, improving performance for containers with many non-interactive children.
// Container with many visual-only children
const container = new Container();
container.interactiveChildren = false; // Skip hit testing children
// Menu with interactive buttons
const menu = new Container();
menu.interactiveChildren = true; // Test all children
menu.addChild(button1, button2, button3);
// Performance optimization
background.interactiveChildren = false;
foreground.interactiveChildren = true;
Readonly ExperimentalisWhether this container is currently cached as a texture.
ExperimentalisDetermines if the container is interactive or not
Whether the container is interactive or not
import { Sprite } from 'pixi.js';
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
sprite.isInteractive(); // true
sprite.eventMode = 'dynamic';
sprite.isInteractive(); // true
sprite.eventMode = 'none';
sprite.isInteractive(); // false
sprite.eventMode = 'passive';
sprite.isInteractive(); // false
sprite.eventMode = 'auto';
sprite.isInteractive(); // false
ExperimentallabelThe instance label of the object.
ExperimentallinesLine segments of the text, each containing one or more words.
Readonly ExperimentallocalCurrent transform of the object based on local factors: position, scale, other stuff. This matrix represents the local transformation without any parent influence.
// Basic transform access
const localMatrix = sprite.localTransform;
console.log(localMatrix.toString());
ExperimentalmaskSets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it.
In PixiJS a regular mask must be a Graphics or a Sprite object.
This allows for much faster masking in canvas as it utilities shape clipping.
Furthermore, a mask of an object must be in the subtree of its parent.
Otherwise, getLocalBounds may calculate incorrect bounds, which makes the container's width and height wrong.
For sprite mask both alpha and red channel are used. Black mask is the same as transparent mask.
// Apply mask to sprite
const sprite = new Sprite(texture);
sprite.mask = graphics;
// Remove mask
sprite.mask = null;
ExperimentalnameThe instance name of the object.
Optional ExperimentalonclickProperty-based event handler for the click event.
Fired when a pointer device (mouse, touch, etc.) completes a click action.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('click', (event) => {
console.log('Sprite clicked at:', event.global.x, event.global.y);
});
// Using property-based handler
sprite.onclick = (event) => {
console.log('Clicked at:', event.global.x, event.global.y);
};
Optional ExperimentalonglobalmousemoveProperty-based event handler for the globalmousemove event.
Fired when the mouse moves anywhere, regardless of whether the pointer is over this object.
The object must have eventMode set to 'static' or 'dynamic' to receive this event.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('globalmousemove', (event) => {
// Move sprite to mouse position
sprite.position.copyFrom(event.global);
});
// Using property-based handler
sprite.onglobalmousemove = (event) => {
// Move sprite to mouse position
sprite.position.copyFrom(event.global);
};
Optional ExperimentalonglobalpointermoveProperty-based event handler for the globalpointermove event.
Fired when the pointer moves anywhere, regardless of whether the pointer is over this object.
The object must have eventMode set to 'static' or 'dynamic' to receive this event.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('globalpointermove', (event) => {
sprite.position.set(event.global.x, event.global.y);
});
// Using property-based handler
sprite.onglobalpointermove = (event) => {
sprite.position.set(event.global.x, event.global.y);
};
Optional ExperimentalonglobaltouchmoveProperty-based event handler for the globaltouchmove event.
Fired when a touch interaction moves anywhere, regardless of whether the pointer is over this object.
The object must have eventMode set to 'static' or 'dynamic' to receive this event.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('globaltouchmove', (event) => {
sprite.position.set(event.global.x, event.global.y);
});
// Using property-based handler
sprite.onglobaltouchmove = (event) => {
sprite.position.set(event.global.x, event.global.y);
};
Optional ExperimentalonmousedownProperty-based event handler for the mousedown event.
Fired when a mouse button is pressed while the pointer is over the object.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('mousedown', (event) => {
sprite.alpha = 0.5; // Visual feedback
console.log('Mouse button:', event.button);
});
// Using property-based handler
sprite.onmousedown = (event) => {
sprite.alpha = 0.5; // Visual feedback
console.log('Mouse button:', event.button);
};
Optional ExperimentalonmouseenterProperty-based event handler for the mouseenter event.
Fired when the mouse pointer enters the bounds of the object. Does not bubble.
Optional ExperimentalonmouseleaveProperty-based event handler for the mouseleave event.
Fired when the pointer leaves the bounds of the display object. Does not bubble.
Optional ExperimentalonmousemoveProperty-based event handler for the mousemove event.
Fired when the pointer moves while over the display object.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('mousemove', (event) => {
// Get coordinates relative to the sprite
console.log('Local:', event.getLocalPosition(sprite));
});
// Using property-based handler
sprite.onmousemove = (event) => {
// Get coordinates relative to the sprite
console.log('Local:', event.getLocalPosition(sprite));
};
Optional ExperimentalonmouseoutProperty-based event handler for the mouseout event.
Fired when the pointer moves out of the bounds of the display object.
Optional ExperimentalonmouseoverProperty-based event handler for the mouseover event.
Fired when the pointer moves onto the bounds of the display object.
Optional ExperimentalonmouseupProperty-based event handler for the mouseup event.
Fired when a mouse button is released over the display object.
Optional ExperimentalonmouseupoutsideProperty-based event handler for the mouseupoutside event.
Fired when a mouse button is released outside the display object that initially
registered a mousedown.
Optional ExperimentalonpointercancelProperty-based event handler for the pointercancel event.
Fired when a pointer device interaction is canceled or lost.
Optional ExperimentalonpointerdownProperty-based event handler for the pointerdown event.
Fired when a pointer device button (mouse, touch, pen, etc.) is pressed.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('pointerdown', (event) => {
sprite.position.set(event.global.x, event.global.y);
});
// Using property-based handler
sprite.onpointerdown = (event) => {
sprite.position.set(event.global.x, event.global.y);
};
Optional ExperimentalonpointerenterProperty-based event handler for the pointerenter event.
Fired when a pointer device enters the bounds of the display object. Does not bubble.
Optional ExperimentalonpointerleaveProperty-based event handler for the pointerleave event.
Fired when a pointer device leaves the bounds of the display object. Does not bubble.
Optional ExperimentalonpointermoveProperty-based event handler for the pointermove event.
Fired when a pointer device moves while over the display object.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('pointermove', (event) => {
sprite.position.set(event.global.x, event.global.y);
});
// Using property-based handler
sprite.onpointermove = (event) => {
sprite.position.set(event.global.x, event.global.y);
};
Optional ExperimentalonpointeroutProperty-based event handler for the pointerout event.
Fired when the pointer moves out of the bounds of the display object.
Optional ExperimentalonpointeroverProperty-based event handler for the pointerover event.
Fired when the pointer moves over the bounds of the display object.
Optional ExperimentalonpointertapProperty-based event handler for the pointertap event.
Fired when a pointer device completes a tap action (e.g., touch or mouse click).
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('pointertap', (event) => {
console.log('Sprite tapped at:', event.global.x, event.global.y);
});
// Using property-based handler
sprite.onpointertap = (event) => {
console.log('Sprite tapped at:', event.global.x, event.global.y);
};
Optional ExperimentalonpointerupProperty-based event handler for the pointerup event.
Fired when a pointer device button (mouse, touch, pen, etc.) is released.
Optional ExperimentalonpointerupoutsideProperty-based event handler for the pointerupoutside event.
Fired when a pointer device button is released outside the bounds of the display object
that initially registered a pointerdown.
ExperimentalonThis callback is used when the container is rendered. It runs every frame during the render process, making it ideal for per-frame updates and animations.
In v7 many users used updateTransform for this, however the way v8 renders objects is different
and "updateTransform" is no longer called every frame
// Basic rotation animation
const container = new Container();
container.onRender = () => {
container.rotation += 0.01;
};
// Cleanup when done
container.onRender = null; // Removes callback
Renderer For renderer capabilities
Optional ExperimentalonrightclickProperty-based event handler for the rightclick event.
Fired when a right-click (context menu) action is performed on the object.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('rightclick', (event) => {
console.log('Right-clicked at:', event.global.x, event.global.y);
});
// Using property-based handler
sprite.onrightclick = (event) => {
console.log('Right-clicked at:', event.global.x, event.global.y);
};
Optional ExperimentalonrightdownProperty-based event handler for the rightdown event.
Fired when a right mouse button is pressed down over the display object.
Optional ExperimentalonrightupProperty-based event handler for the rightup event.
Fired when a right mouse button is released over the display object.
Optional ExperimentalonrightupoutsideProperty-based event handler for the rightupoutside event.
Fired when a right mouse button is released outside the bounds of the display object
that initially registered a rightdown.
Optional ExperimentalontapProperty-based event handler for the tap event.
Fired when a tap action (touch) is completed on the object.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('tap', (event) => {
console.log('Sprite tapped at:', event.global.x, event.global.y);
});
// Using property-based handler
sprite.ontap = (event) => {
console.log('Sprite tapped at:', event.global.x, event.global.y);
};
Optional ExperimentalontouchcancelProperty-based event handler for the touchcancel event.
Fired when a touch interaction is canceled, such as when the touch is interrupted.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('touchcancel', (event) => {
console.log('Touch canceled at:', event.global.x, event.global.y);
});
// Using property-based handler
sprite.ontouchcancel = (event) => {
console.log('Touch canceled at:', event.global.x, event.global.y);
};
Optional ExperimentalontouchendProperty-based event handler for the touchend event.
Fired when a touch interaction ends, such as when the finger is lifted from the screen.
Optional ExperimentalontouchendoutsideProperty-based event handler for the touchendoutside event.
Fired when a touch interaction ends outside the bounds of the display object
that initially registered a touchstart.
Optional ExperimentalontouchmoveProperty-based event handler for the touchmove event.
Fired when a touch interaction moves while over the display object.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('touchmove', (event) => {
sprite.position.set(event.global.x, event.global.y);
});
// Using property-based handler
sprite.ontouchmove = (event) => {
sprite.position.set(event.global.x, event.global.y);
};
Optional ExperimentalontouchstartProperty-based event handler for the touchstart event.
Fired when a touch interaction starts, such as when a finger touches the screen.
Optional ExperimentalonwheelProperty-based event handler for the wheel event.
Fired when the mouse wheel is scrolled while over the display object.
const sprite = new Sprite(texture);
sprite.eventMode = 'static';
// Using emitter handler
sprite.on('wheel', (event) => {
sprite.scale.x += event.deltaY * 0.01; // Zoom in/out
sprite.scale.y += event.deltaY * 0.01; // Zoom in/out
});
// Using property-based handler
sprite.onwheel = (event) => {
sprite.scale.x += event.deltaY * 0.01; // Zoom in/out
sprite.scale.y += event.deltaY * 0.01; // Zoom in/out
};
Readonly ExperimentalparentThe display object container that contains this display object. This represents the parent-child relationship in the display tree.
// Basic parent access
const parent = sprite.parent;
// Walk up the tree
let current = sprite;
while (current.parent) {
console.log('Level up:', current.parent.constructor.name);
current = current.parent;
}
Readonly Advanced ExperimentalparentThe RenderLayer this container belongs to, if any. If it belongs to a RenderLayer, it will be rendered from the RenderLayer's position in the scene.
Readonly Advanced ExperimentalrelativeThe relative group transform is a transform relative to the render group it belongs too. It will include all parent transforms and up to the render group (think of it as kind of like a stage - but the stage can be nested). If this container is is self a render group matrix will be relative to its parent render group
ExperimentalsortableIf set to true, the container will sort its children by zIndex value
when the next render is called, or manually if sortChildren() is called.
This actually changes the order of elements in the array of children, so it will affect the rendering order.
Also be aware of that this may not work nicely with the addChildAt() function,
as the zIndex sorting may cause the child to automatically sorted to another position.
ExperimentalsortSorts children by zIndex value. Only sorts if container is marked as dirty.
Optional ExperimentaltabSets the tabIndex of the shadow div. You can use this to set the order of the elements when using the tab key to navigate.
ExperimentalupdateUpdates the cached texture of this container. This will flag the container's cached texture to be redrawn on the next render.
ExperimentalwordsWord segments of the text, each containing one or more characters.
ExperimentalzThe zIndex of the container.
Controls the rendering order of children within their parent container.
A higher value will mean it will be moved towards the front of the rendering order.
// Add in any order
container.addChild(character, background, foreground);
// Adjust rendering order
background.zIndex = 0;
character.zIndex = 1;
foreground.zIndex = 2;
Static ExperimentaldefaultDefault configuration options for SplitBitmapText instances.
ExperimentalThe opacity of the object relative to its parent's opacity. Value ranges from 0 (fully transparent) to 1 (fully opaque).
// Basic transparency
sprite.alpha = 0.5; // 50% opacity
// Inherited opacity
container.alpha = 0.5;
const child = new Sprite(texture);
child.alpha = 0.5;
container.addChild(child);
// child's effective opacity is 0.25 (0.5 * 0.5)
ExperimentalExperimentalThe angle of the object in degrees.
'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees.
// Basic angle rotation
sprite.angle = 45; // 45 degrees
// Rotate around center
sprite.pivot.set(sprite.width / 2, sprite.height / 2);
sprite.angle = 180; // Half rotation
// Rotate around center with origin
sprite.origin.set(sprite.width / 2, sprite.height / 2);
sprite.angle = 180; // Half rotation
// Reset rotation
sprite.angle = 0;
ExperimentalExperimentalThe blend mode to be applied to the sprite. Controls how pixels are blended when rendering.
Setting to 'normal' will reset to default blending.
More blend modes are available after importing the pixi.js/advanced-blend-modes sub-export.
// Basic blend modes
sprite.blendMode = 'add'; // Additive blending
sprite.blendMode = 'multiply'; // Multiply colors
sprite.blendMode = 'screen'; // Screen blend
// Reset blend mode
sprite.blendMode = 'normal'; // Normal blending
ExperimentalGets or sets the transform anchor for character segments. The anchor point determines the center of rotation and scaling for each character.
ExperimentalSets the filters for the displayObject. Filters are visual effects that can be applied to any display object and its children.
This is a WebGL/WebGPU only feature and will be ignored by the canvas renderer.
// Add a single filter
sprite.filters = new BlurFilter(2);
// Apply multiple filters
container.filters = [
new BlurFilter(2),
new ColorMatrixFilter(),
];
// Remove filters
sprite.filters = null;
Filter For filter base class
ExperimentalThe height of the Container,
Changing the height will adjust the scale.y property of the container while maintaining its aspect ratio. [!NOTE] If you want to set both width and height at the same time, use Container#setSize as it is more optimized by not recalculating the local bounds twice.
ExperimentalAdvanced ExperimentalWhether or not the object should be rendered.
Advanced ExperimentalReturns true if this container is a render group. This means that it will be rendered as a separate pass, with its own set of instructions
ExperimentalExperimentalGets or sets the transform anchor for line segments. The anchor point determines the center of rotation and scaling for each line.
ExperimentalThe origin point around which the container rotates and scales without affecting its position. Unlike pivot, changing the origin will not move the container's position.
ExperimentalThe center of rotation, scaling, and skewing for this display object in its local space.
The position is the projection of pivot in the parent's local space.
By default, the pivot is the origin (0, 0).
ExperimentalThe coordinate of the object relative to the local coordinates of the parent.
ExperimentalControls whether this object can be rendered. If false the object will not be drawn, but the transform will still be updated. This is different from visible, which skips transform updates.
// Basic render control
sprite.renderable = false; // Skip rendering
sprite.renderable = true; // Enable rendering
ExperimentalExperimentalThe rotation of the object in radians.
'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees.
// Basic rotation
container.rotation = Math.PI / 4; // 45 degrees
// Convert from degrees
const degrees = 45;
container.rotation = degrees * Math.PI / 180;
// Rotate around center
container.pivot.set(container.width / 2, container.height / 2);
container.rotation = Math.PI; // 180 degrees
// Rotate around center with origin
container.origin.set(container.width / 2, container.height / 2);
container.rotation = Math.PI; // 180 degrees
ExperimentalExperimentalThe scale factors of this object along the local coordinate axes.
The default scale is (1, 1).
ExperimentalThe skew factor for the object in radians. Skewing is a transformation that distorts the object by rotating it differently at each point, creating a non-uniform shape.
// Basic skewing
container.skew.set(0.5, 0); // Skew horizontally
container.skew.set(0, 0.5); // Skew vertically
// Skew with point data
container.skew = { x: 0.3, y: 0.3 }; // Diagonal skew
// Reset skew
container.skew.set(0, 0);
// Animate skew
app.ticker.add(() => {
// Create wave effect
container.skew.x = Math.sin(Date.now() / 1000) * 0.3;
});
// Combine with rotation
container.rotation = Math.PI / 4; // 45 degrees
container.skew.set(0.2, 0.2); // Skew the rotated object
ExperimentalExperimentalThe style configuration for the text. Can be a TextStyle instance or a configuration object.
const text = new Text({
text: 'Styled Text',
style: {
fontSize: 24,
fill: 0xff1010, // Red color
fontFamily: 'Arial',
align: 'center', // Center alignment
stroke: { color: '#4a1850', width: 5 }, // Purple stroke
dropShadow: {
color: '#000000', // Black shadow
blur: 4, // Shadow blur
distance: 6 // Shadow distance
}
}
});
// Update style dynamically
text.style = {
fontSize: 30, // Change font size
fill: 0x00ff00, // Change color to green
align: 'right', // Change alignment to right
stroke: { color: '#000000', width: 2 }, // Add black stroke
ExperimentalExperimentalGets or sets the text content. Setting new text triggers splitting if autoSplit is true.
Setting this frequently can have a performance impact, especially with large texts and canvas text.
ExperimentalThe tint applied to the sprite.
This can be any valid ColorSource.
// Basic color tinting
container.tint = 0xff0000; // Red tint
container.tint = 'red'; // Same as above
container.tint = '#00ff00'; // Green
container.tint = 'rgb(0,0,255)'; // Blue
// Remove tint
container.tint = 0xffffff; // White = no tint
container.tint = null; // Also removes tint
ExperimentalThe visibility of the object. If false the object will not be drawn, and the transform will not be updated.
// Basic visibility toggle
sprite.visible = false; // Hide sprite
sprite.visible = true; // Show sprite
ExperimentalExperimentalThe width of the Container, setting this will actually modify the scale to achieve the value set.
Changing the width will adjust the scale.x property of the container while maintaining its aspect ratio. [!NOTE] If you want to set both width and height at the same time, use Container#setSize as it is more optimized by not recalculating the local bounds twice.
ExperimentalExperimentalGets or sets the transform anchor for word segments. The anchor point determines the center of rotation and scaling for each word.
ExperimentalCurrent transform of the object based on world (parent) factors.
This matrix represents the absolute transformation in the scene graph.
// Get world position
const worldPos = container.worldTransform;
console.log(`World position: (${worldPos.tx}, ${worldPos.ty})`);
Container#localTransform For local space transform
ExperimentalExperimentalExperimentalAdds one or more children to the container. The children will be rendered as part of this container's display list.
The Container(s) to add to the container
The first child that was added
// Add a single child
container.addChild(sprite);
// Add multiple children
container.addChild(background, player, foreground);
// Add with type checking
const sprite = container.addChild<Sprite>(new Sprite(texture));
sprite.tint = 'red';
ExperimentalAdds a child to the container at a specified index. If the index is out of bounds an error will be thrown. If the child is already in this container, it will be moved to the specified index.
The child to add
The index where the child will be placed
The child that was added
// Add at specific index
container.addChildAt(sprite, 0); // Add to front
// Move existing child
const index = container.children.length - 1;
container.addChildAt(existingChild, index); // Move to back
// With error handling
try {
container.addChildAt(sprite, 1000);
} catch (e) {
console.warn('Index out of bounds');
}
ExperimentalUnlike on or addListener which are methods from EventEmitter, addEventListener
seeks to be compatible with the DOM's addEventListener with support for options.
The type of event to listen to.
The listener callback or object.
Optionaloptions: AddListenerOptionsListener options, used for capture phase.
// Tell the user whether they did a single, double, triple, or nth click.
button.addEventListener('click', {
handleEvent(e): {
let prefix;
switch (e.detail) {
case 1: prefix = 'single'; break;
case 2: prefix = 'double'; break;
case 3: prefix = 'triple'; break;
default: prefix = e.detail + 'th'; break;
}
console.log('That was a ' + prefix + 'click');
}
});
// But skip the first click!
button.parent.addEventListener('click', function blockClickOnce(e) {
e.stopImmediatePropagation();
button.parent.removeEventListener('click', blockClickOnce, true);
}, {
capture: true,
});
ExperimentalOptionaloptions: AddListenerOptionsExperimentalDestroys the SplitText instance and all its resources. Cleans up all segment arrays, event listeners, and optionally the text style.
Optionaloptions: DestroyOptionsDestroy configuration options
Advanced ExperimentalThis will disable the render group for this container.
ExperimentalDispatch the event on this Container using the event's EventBoundary.
The target of the event is set to this and the defaultPrevented flag is cleared before dispatch.
The event to dispatch.
Whether the preventDefault() method was not invoked.
Advanced ExperimentalCalling this enables a render group for this container. This means it will be rendered as a separate set of instructions. The transform of the container will also be handled on the GPU rather than the CPU.
ExperimentalCalculates and returns the (world) bounds of the display object as a Rectangle. Takes into account transforms and child bounds.
OptionalskipUpdate: booleanSetting to true will stop the transforms of the scene graph from
being updated. This means the calculation returned MAY be out of date BUT will give you a
nice performance boost.
Optionalbounds: BoundsOptional bounds to store the result of the bounds calculation
The minimum axis-aligned rectangle in world space that fits around this object
// Basic bounds calculation
const bounds = sprite.getBounds();
console.log(`World bounds: ${bounds.x}, ${bounds.y}, ${bounds.width}, ${bounds.height}`);
// Reuse bounds object for performance
const recycleBounds = new Bounds();
sprite.getBounds(false, recycleBounds);
// Skip update for performance
const fastBounds = sprite.getBounds(true);
ExperimentalReturns the child at the specified index.
The index to get the child from
The child at the given index
// Get first child
const first = container.getChildAt(0);
// Type-safe access
const sprite = container.getChildAt<Sprite>(1);
// With error handling
try {
const child = container.getChildAt(10);
} catch (e) {
console.warn('Index out of bounds');
}
ExperimentalReturns the first child in the container with the specified label. Recursive searches are done in a pre-order traversal.
Instance label to search for
Optionaldeep: booleanWhether to search recursively through children
The first child with the specified label, or null if none found
// Basic label search
const child = container.getChildByLabel('player');
// Search with regular expression
const enemy = container.getChildByLabel(/enemy-\d+/);
// Deep search through children
const deepChild = container.getChildByLabel('powerup', true);
ExperimentalInstance name.
Optionaldeep: booleanWhether to search recursively
The child with the specified name.
ExperimentalReturns the index position of a child Container instance.
The Container instance to identify
The index position of the child container
// Basic index lookup
const index = container.getChildIndex(sprite);
console.log(`Sprite is at index ${index}`);
// With error handling
try {
const index = container.getChildIndex(sprite);
} catch (e) {
console.warn('Child not found in container');
}
ExperimentalReturns all children in the container with the specified label. Recursive searches are done in a pre-order traversal.
Instance label to search for
Optionaldeep: booleanWhether to search recursively through children
Optionalout: Container<ContainerChild>[]Optional array to store matching children in
An array of children with the specified label
// Basic label search
const enemies = container.getChildrenByLabel('enemy');
// Search with regular expression
const powerups = container.getChildrenByLabel(/powerup-\d+/);
// Deep search with collection
const buttons = [];
container.getChildrenByLabel('button', true, buttons);
Advanced ExperimentalComputes an approximate global bounding box for the container and its children. This method is optimized for speed by using axis-aligned bounding boxes (AABBs), and uses the last render results from when it updated the transforms. This function does not update them. which may result in slightly larger bounds but never smaller than the actual bounds.
for accurate (but less performant) results use container.getGlobalBounds
OptionalfactorRenderLayers: booleanA flag indicating whether to consider render layers in the calculation.
Optionalbounds: BoundsThe output bounds object to store the result. If not provided, a new one is created.
The computed bounds.
ExperimentalReturns the global (compound) alpha of the container within the scene.
OptionalskipUpdate: booleanPerformance optimization flag:
The resulting alpha value (between 0 and 1)
ExperimentalReturns the global position of the container, taking into account the container hierarchy.
Optionalpoint: PointThe optional point to write the global value to
OptionalskipUpdate: booleanShould we skip the update transform
The updated point
// Basic position check
const globalPos = sprite.getGlobalPosition();
console.log(`Global: (${globalPos.x}, ${globalPos.y})`);
// Reuse point object
const point = new Point();
sprite.getGlobalPosition(point);
// Skip transform update for performance
const fastPos = container.getGlobalPosition(undefined, true);
ExperimentalReturns the global (compound) tint color of the container within the scene.
OptionalskipUpdate: booleanPerformance optimization flag:
The resulting tint color as a 24-bit RGB number (0xRRGGBB)
ExperimentalReturns the global transform matrix of the container within the scene.
Optionalmatrix: MatrixOptional matrix to store the result. If not provided, a new Matrix will be created.
OptionalskipUpdate: booleanPerformance optimization flag:
The resulting transformation matrix (either the input matrix or a new one)
// Accurate but slower - recalculates entire transform chain
const preciseTransform = container.getGlobalTransform();
// Faster but may be outdated - uses cached transform
const cachedTransform = container.getGlobalTransform(undefined, true);
// Reuse existing matrix
const existingMatrix = new Matrix();
container.getGlobalTransform(existingMatrix);
ExperimentalRetrieves the local bounds of the container as a Bounds object. Uses cached values when possible for better performance.
The bounding area
// Basic bounds check
const bounds = container.getLocalBounds();
console.log(`Width: ${bounds.width}, Height: ${bounds.height}`);
// subsequent calls will reuse the cached bounds
const cachedBounds = container.getLocalBounds();
console.log(bounds === cachedBounds); // true
ExperimentalRemoves one or more children from the container. When removing multiple children, events will be triggered for each child in sequence.
The Container(s) to remove
The first child that was removed
// Remove a single child
const removed = container.removeChild(sprite);
// Remove multiple children
const bg = container.removeChild(background, player, userInterface);
// Remove with type checking
const sprite = container.removeChild<Sprite>(childSprite);
sprite.texture = newTexture;
ExperimentalRemoves a child from the specified index position.
The index to remove the child from
The child that was removed
// Remove first child
const removed = container.removeChildAt(0);
// type safe access
const sprite = container.removeChildAt<Sprite>(1);
// With error handling
try {
const child = container.removeChildAt(10);
} catch (e) {
console.warn('Index out of bounds');
}
ExperimentalRemoves all children from this container that are within the begin and end indexes.
OptionalbeginIndex: numberThe beginning position
OptionalendIndex: numberThe ending position. Default is container size
List of removed children
// Remove all children
container.removeChildren();
// Remove first 3 children
const removed = container.removeChildren(0, 3);
console.log('Removed:', removed.length); // 3
// Remove children from index 2 onwards
container.removeChildren(2);
// Remove specific range
const middle = container.removeChildren(1, 4);
ExperimentalUnlike off or removeListener which are methods from EventEmitter, removeEventListener
seeks to be compatible with the DOM's removeEventListener with support for options.
The type of event the listener is bound to.
The listener callback or object.
Optionaloptions: RemoveListenerOptionsThe original listener options. This is required to deregister a capture phase listener.
ExperimentalOptionaloptions: RemoveListenerOptionsExperimentalRemove the Container from its parent Container. If the Container has no parent, do nothing.
// Basic removal
sprite.removeFromParent();
// With validation
if (sprite.parent) {
sprite.removeFromParent();
}
ExperimentalReparent a child or multiple children to this container while preserving their world transform. This ensures that the visual position and rotation of the children remain the same even when changing parents.
The child or children to reparent
The first child that was reparented
// Basic reparenting
const sprite = new Sprite(texture);
oldContainer.addChild(sprite);
// Move to new parent, keeping visual position
newContainer.reparentChild(sprite);
// Reparent multiple children
const batch = [sprite1, sprite2, sprite3];
newContainer.reparentChild(...batch);
ExperimentalReparent the child to this container at the specified index while preserving its world transform. This ensures that the visual position and rotation of the child remain the same even when changing parents.
The child to reparent
The index to reparent the child to
The reparented child
// Basic index-specific reparenting
const sprite = new Sprite(texture);
oldContainer.addChild(sprite);
// Move to new parent at index 0 (front)
newContainer.reparentChildAt(sprite, 0);
ExperimentalReplace a child in the container with a new child. Copying the local transform from the old child to the new one.
ExperimentalChanges the position of an existing child in the container.
The child Container instance to reposition
The resulting index number for the child
// Basic index change
container.setChildIndex(sprite, 0); // Move to front
container.setChildIndex(sprite, container.children.length - 1); // Move to back
// With error handling
try {
container.setChildIndex(sprite, 5);
} catch (e) {
console.warn('Invalid index or child not found');
}
ExperimentalUpdates the local transform properties by decomposing the given matrix. Extracts position, scale, rotation, and skew from a transformation matrix.
The matrix to use for updating the transform
// Basic matrix transform
const matrix = new Matrix()
.translate(100, 100)
.rotate(Math.PI / 4)
.scale(2, 2);
container.setFromMatrix(matrix);
// Copy transform from another container
const source = new Container();
source.position.set(100, 100);
source.rotation = Math.PI / 2;
target.setFromMatrix(source.localTransform);
// Reset transform
container.setFromMatrix(Matrix.IDENTITY);
ExperimentalUsed to set mask and control mask options on a display object. Allows for more detailed control over masking behavior compared to the mask property.
Configuration options for the mask
import { Graphics, Sprite } from 'pixi.js';
// Create a circular mask
const graphics = new Graphics()
.beginFill(0xFF3300)
.drawCircle(100, 100, 50)
.endFill();
// Apply mask with options
sprite.setMask({
mask: graphics,
inverse: true, // Create a hole effect
});
// Clear existing mask
sprite.setMask({ mask: null });
ExperimentalSets the size of the container to the specified width and height. This is more efficient than setting width and height separately as it only recalculates bounds once.
ExperimentalSplits the text into lines, words, and characters. Call this manually when autoSplit is false.
ExperimentalSwaps the position of 2 Containers within this container.
// Basic swap
container.swapChildren(sprite1, sprite2);
// With error handling
try {
container.swapChildren(sprite1, sprite2);
} catch (e) {
console.warn('One or both children not found in container');
}
ExperimentalCalculates the global position of a point relative to this container. Takes into account the container hierarchy and transforms.
The global position
// Basic point conversion
const localPoint = { x: 10, y: 20 };
const globalPoint = container.toGlobal(localPoint);
// With point reuse
const reusePoint = new Point();
container.toGlobal(localPoint, reusePoint);
// Performance optimization
const fastPoint = container.toGlobal(
{ x: 50, y: 50 },
undefined,
true // Skip transform update
);
ExperimentalCalculates the local position of the container relative to another point. Converts coordinates from any coordinate space to this container's local coordinate space.
A point object representing the position in local space
// Basic coordinate conversion
const worldPoint = { x: 100, y: 100 };
const localPos = container.toLocal(worldPoint);
// Convert from another container
const fromSprite = new Sprite(texture);
fromSprite.position.set(50, 50);
const pointInSprite = { x: 10, y: 10 };
const localPoint = container.toLocal(pointInSprite, fromSprite);
// With point reuse for performance
const reusePoint = new Point();
container.toLocal(worldPoint, undefined, reusePoint);
// Skip transform update for static objects
const fastLocal = container.toLocal(
worldPoint,
undefined,
undefined,
true
);
ExperimentalUpdates the local transform.
ExperimentalUpdates the transform properties of the container. Allows partial updates of transform properties for optimized manipulation.
Transform options to update
The x position
The y position
The x-axis scale factor
The y-axis scale factor
The rotation in radians
The x-axis skew factor
The y-axis skew factor
The x-axis pivot point
The y-axis pivot point
This container, for chaining
// Basic transform update
container.updateTransform({
x: 100,
y: 200,
rotation: Math.PI / 4
});
// Scale and rotate around center
sprite.updateTransform({
pivotX: sprite.width / 2,
pivotY: sprite.height / 2,
scaleX: 2,
scaleY: 2,
rotation: Math.PI
});
// Update position only
button.updateTransform({
x: button.x + 10, // Move right
y: button.y // Keep same y
});
StaticfromExperimentalCreates a SplitBitmapText instance from an existing text object. Useful for converting standard Text or BitmapText objects into segmented versions.
The source text object to convert
Optionaloptions: Omit<SplitBitmapTextOptions, "text" | "style">Additional splitting options
A new SplitBitmapText instance
const bitmapText = new BitmapText({
text: 'Bitmap Text',
style: { fontFamily: 'Arial' }
});
const segmented = SplitBitmapText.from(bitmapText);
// with additional options
const segmentedWithOptions = SplitBitmapText.from(bitmapText, {
autoSplit: false,
lineAnchor: 0.5,
wordAnchor: { x: 0, y: 0.5 },
})
StaticmixinExperimentalMixes all enumerable properties and methods from a source object to Container.
The source of properties and methods to mix in.
A container that splits text into individually manipulatable segments (lines, words, and characters) for advanced text effects and animations. Converts each segment into a separate BitmapText object.
Example: Basic Usage
Features:
Example: Animation Example
Configuration Options:
text: The string to render and segmentstyle: TextStyle instance or configuration objectautoSplit: Automatically update segments on changes (default: true)lineAnchor: Transform origin for lines (default: 0)wordAnchor: Transform origin for words (default: 0)charAnchor: Transform origin for characters (default: 0)Anchor points are normalized (0-1):
Limitations