Skip to main content

Overview

Containers group display objects and control their position, visibility, and layer order. Graphics components let you draw shapes programmatically using the PixiJS graphics API.

Coordinate system

PixiJS uses a top-left originx=0, y=0 is the top-left corner of the canvas. The x axis increases to the right, and the y axis increases downward. The anchor prop on shape components shifts the pivot point of the object. anchor={0} (default) places the origin at the top-left of the object. anchor={0.5} centres it. anchor={1} places it at the bottom-right.

<Container>

A transparent display-object group. Nest other components inside it to control their collective position, scale, alpha, and z-order. <Container> accepts all props from PIXI.ContainerOptions. The most commonly used props are listed below.

Props

number
Horizontal position in pixels from the parent’s origin. Default 0.
number
Vertical position in pixels from the parent’s origin. Default 0.
number
Override the container’s width. Scales child content to fit.
number
Override the container’s height. Scales child content to fit.
number | PointData
Uniform scale (number) or per-axis scale ({ x, y }). Default 1.
number
Opacity from 0 (invisible) to 1 (fully opaque). Default 1.
boolean
When false, the container and all its children are hidden and excluded from rendering. Default true.
number
Sort order within the parent container. Higher values render on top. Default 0.
number
Rotation in radians. Default 0.
number | PointData
The pivot point used for rotation and scaling, in local coordinates.
boolean
When true, children are automatically sorted by zIndex before each render. Default false.
boolean
When false, pointer events are disabled for all children. Default true.
Cursor
CSS cursor string shown when the pointer is over this container. Accepts standard CSS cursor values.
Snippet
required
Child components to render inside this container.

Example


<Graphics>

Renders arbitrary shapes using a draw callback. The callback receives a PIXI.Graphics instance and is re-run reactively whenever the draw prop changes.

Props

(graphics: PIXI.Graphics) => void
required
A function called with the PIXI.Graphics object. Use the full PixiJS graphics API inside this function to draw shapes, lines, fills, and strokes. The graphics context is cleared before each call.
boolean
When true, this graphics object is applied as a mask to the parent container. When false or omitted, the mask is removed. Default undefined.
number
Horizontal position. Default 0.
number
Vertical position. Default 0.
number
Opacity from 0 to 1. Default 1.
boolean
Whether the graphic is rendered. Default true.
number
Sort order within the parent. Default 0.
Cursor
CSS cursor string for pointer interaction.

Example


<Circle>

A convenience wrapper around <Graphics> that draws a filled circle with an optional border. Supports the anchor prop to control the pivot point.

Props

number
required
The diameter of the circle in pixels.
PixiPoint
Controls the pivot point. 0 = top-left, 0.5 = centre, 1 = bottom-right. Accepts a number (uniform) or { x, y }. Default undefined (top-left).
PIXI.ColorSource
Fill colour. Accepts hex numbers (0xff0000), CSS colour strings ('#ff0000'), or RGB arrays. Default 0x000000.
number
Fill opacity from 0 to 1. Default 1.
PIXI.ColorSource
Stroke colour. Default 0x000000.
number
Stroke width in pixels. Default 0 (no border).
number
Stroke opacity from 0 to 1. Default 1.
number
Horizontal position. Default 0.
number
Vertical position. Default 0.
number
Object opacity. Default 1.
boolean
Whether the circle is rendered. Default true.
number
Sort order within the parent. Default 0.
boolean
Apply this circle as a mask on the parent container.
Cursor
CSS cursor string.

Example


<Rectangle>

A convenience wrapper around <Graphics> that draws a filled rectangle with optional rounded corners and border. Supports the anchor prop.

Props

number
required
Width of the rectangle in pixels.
number
required
Height of the rectangle in pixels.
PixiPoint
Controls the pivot point. 0 = top-left, 0.5 = centre. Default undefined (top-left).
number
Corner radius for rounded rectangles. 0 = sharp corners. Default 0.
PIXI.ColorSource
Fill colour. Default 0x000000.
number
Fill opacity from 0 to 1. Default 1.
PIXI.ColorSource
Stroke colour. Default 0x000000.
number
Stroke width in pixels. Default 0 (no border).
number
Stroke opacity from 0 to 1. Default 1.
number
Horizontal position. Default 0.
number
Vertical position. Default 0.
number
Object opacity. Default 1.
boolean
Whether the rectangle is rendered. Default true.
number
Sort order within the parent. Default 0.
boolean
Apply this rectangle as a mask on the parent container.
Cursor
CSS cursor string.

Example


Using Graphics as a mask

Set isMask={true} on any <Graphics>, <Circle>, or <Rectangle> to clip the parent container to that shape.