Skip to main content

Object Fit

Important!

objectFit only applies to leaf nodes

The objectFit property defines how an object (like a Sprite, Text, or Graphics) is resized to fit inside its layout box.

ValueDescription
containScale the object as large as possible while keeping its aspect ratio and fitting entirely inside the container.
coverScale the object to completely cover the container while maintaining aspect ratio. Some parts may be clipped.
fillStretch the object to exactly fill the container. Aspect ratio may be distorted.
noneNo scaling. The object retains its original size.
scale-downSame as none or contain, whichever results in a smaller object.
sprite.layout = {
width: 200,
height: 200,
objectFit: 'contain',
};

Object Position

Important!

objectPosition only applies to leaf nodes

The objectPosition property defines where the object is anchored inside its layout box after scaling.

It accepts:

  • Simple keywords like 'center', 'top left', 'bottom right'
  • More advanced four-part values like 'bottom 10px right 20px'

This allows very fine-grained control over content alignment inside the layout box.

Common keywords

ValueDescription
centerCenter horizontally and vertically (default).
topCenter horizontally, align to top.
bottomCenter horizontally, align to bottom.
leftCenter vertically, align to left.
rightCenter vertically, align to right.
top leftAlign to top-left corner.
top rightAlign to top-right corner.
bottom leftAlign to bottom-left corner.
bottom rightAlign to bottom-right corner.

Advanced syntax: side plus pixel offset

You can specify up to four parts like:

sprite.layout = {
objectPosition: 'bottom 10px right 20px',
};

Meaning:

  • Offset 10px inward from the bottom.
  • Offset 20px inward from the right.

Transform Origin

The transformOrigin property defines the pivot point for rotation and scaling, but applies to the layout box, not the PixiJS element itself. This behavior is conceptually similar to transform-origin in CSS.

For the full breakdown of how it works, see the Transform Origin guide.

It accepts:

  • Simple keywords like 'center', 'top left', 'bottom right'
  • Four-part values like 'top 0px left 50px' for fine-grained offsetting.

Common keywords

ValueDescription
'center' (default)Center of the layout box.
'top left', 'top right'Corners.
'bottom left', 'bottom right'Corners.
'top', 'bottom', 'left', 'right'Edges, centered along the opposite axis.

Advanced syntax: side plus pixel offset

sprite.layout = {
transformOrigin: 'top 0px left 50px',
};

Meaning:

  • Pivot 0px from top.
  • Pivot 50px from left.