Skip to content

Sprite Component

Simple Image:

html
<Sprite 
    image="path/to/image.png"
/>

Part of an image:

html
<Sprite 
    image="path/to/image.png"
    rectangle={{ x: 0, y: 0, width: 100, height: 100 }}
/>

Sprite Sheet:

html
<script>
const definition = {
    id: "hero",
    image: "./hero_2.png",
    width: 1248,
    height: 2016,
    framesWidth: 6,
    framesHeight: 4,
    textures: {
        stand: {
             animations: ({ direction }) => [
                [ { time: 0, frameX: 0, frameY: 0 } ]
             ]
        },
        walk: {
             animations: ({ direction }) => [
                [ 
                  { time: 0, frameX: 0, frameY: 1 },
                  { time: 10, frameX: 1, frameY: 1 },
                  { time: 20, frameX: 2, frameY: 1 }
                ]
             ]
        }
    }
}

const onFinish = () => {
    console.log("Animation finished")
}
</script>

<Sprite 
    sheet={{
        definition,
        playing: "stand",
        params: {
            direction: "right"
        },
        onFinish
    }}
/>

Available Sheet Definition Parameters

ParameterTypeDescription
idstringUnique identifier for the spritesheet
imagestringPath to the spritesheet image
widthnumberTotal width of the spritesheet image
heightnumberTotal height of the spritesheet image
framesWidthnumberNumber of frames horizontally in the spritesheet
framesHeightnumberNumber of frames vertically in the spritesheet
rectWidthnumber(Optional) Width of each frame if not equal to width/framesWidth
rectHeightnumber(Optional) Height of each frame if not equal to height/framesHeight
offset{ x: number, y: number }(Optional) Offset to start frame cutting from
soundstring(Optional) Path to sound file that plays when animation starts
spriteRealSizenumber | { width: number, height: number }(Optional) Real size of sprite for collision detection
anchor[number, number](Optional) Anchor point [x, y] for positioning (0-1)
scale[number, number](Optional) Scale factor [x, y]
skew[number, number](Optional) Skew value [x, y]
pivot[number, number](Optional) Pivot point [x, y] for rotation
opacitynumber(Optional) Opacity value (0-1)
texturesobjectContains named animations and their frame definitions

Animation Frame Parameters

Each frame in an animation can have these properties:

ParameterTypeDescription
timenumberTime (in frames) when this frame should be displayed
frameXnumberHorizontal frame index in the spritesheet
frameYnumberVertical frame index in the spritesheet
xnumber(Optional) X position offset for this frame
ynumber(Optional) Y position offset for this frame
anglenumber(Optional) Rotation angle for this frame
rotationnumber(Optional) Alternative rotation value
visibleboolean(Optional) Whether the frame is visible
opacitynumber(Optional) Frame-specific opacity (0-1)
anchor[number, number](Optional) Frame-specific anchor point
scale[number, number](Optional) Frame-specific scale
skew[number, number](Optional) Frame-specific skew
pivot[number, number](Optional) Frame-specific pivot point
soundstring(Optional) Sound to play when this frame is reached

Sprite Props

PropTypeDescription
imagestringPath to the image (when not using a spritesheet)
rectangle{ x, y, width, height }(Optional) Extract only part of the image
sheetobjectSpritesheet configuration
sheet.definitionobjectThe spritesheet definition object
sheet.playingstringName of the animation to play
sheet.paramsobjectParameters passed to the animation function
sheet.onFinishfunctionCallback when animation completes
loaderobjectLoading configuration
loader.onProgressfunctionProgress callback for loading
loader.onCompletefunctionCompletion callback for loading
scaleModenumberPIXI.js scale mode for the texture

Common Properties

PropertyTypeDescription
xnumberX-coordinate position of the display object.
ynumberY-coordinate position of the display object.
widthnumberWidth of the display object.
heightnumberHeight of the display object.
scaleobjectScale of the display object.
anchorobjectAnchor point of the display object.
skewobjectSkew of the display object.
tintnumberTint color of the display object.
rotationnumberRotation of the display object in radians.
anglenumberRotation of the display object in degrees.
zIndexnumberZ-index of the display object.
roundPixelsbooleanWhether to round pixel values.
cursorstringCursor style when hovering over the display object.
visiblebooleanVisibility of the display object.
alphanumberAlpha transparency of the display object.
pivotobjectPivot point of the display object.
filtersarrayFilters applied to the display object.
maskOfElementElement that this display object masks.
blendModestringBlend mode for rendering.
filterAreaobjectFilter area for rendering.

Layout Properties

Pour obtenir la documentation complète et détaillée sur toutes les propriétés de mise en page, consultez la documentation officielle de PixiJS Layout.

Sizing and Dimensions

PropertyTypeDescription
widthnumber/stringWidth of the display object. Accepts pixels or percentage (e.g. '50%').
heightnumber/stringHeight of the display object. Accepts pixels or percentage (e.g. '50%').
minWidthnumber/stringMinimum width the object can shrink to.
minHeightnumber/stringMinimum height the object can shrink to.
maxWidthnumber/stringMaximum width the object can expand to.
maxHeightnumber/stringMaximum height the object can expand to.
aspectRationumberRatio between width and height (e.g. 1.5 for 3:2 ratio).

Flex Layout

PropertyTypeDescription
flexDirectionstringDirection of flex items. Values: 'row', 'column', 'row-reverse', 'column-reverse'.
flexWrapstringWhether items wrap. Values: 'wrap', 'nowrap', 'wrap-reverse'.
justifyContentstringAlignment along main axis. Values: 'flex-start', 'flex-end', 'center', 'space-between', 'space-around'.
alignItemsstringAlignment along cross axis. Values: 'flex-start', 'flex-end', 'center', 'stretch', 'baseline'.
alignContentstringAlignment of lines with multiple items. Values: 'flex-start', 'flex-end', 'center', 'stretch', 'space-between', 'space-around'.
alignSelfstringOverride of parent's alignItems for specific item.
flexGrownumberGrow factor of item relative to other items.
flexShrinknumberShrink factor of item relative to other items.
flexBasisnumber/stringInitial size of item before flex growing/shrinking.
gapnumber/objectGap between items.
rowGapnumberGap between rows.
columnGapnumberGap between columns.

Positioning

PropertyTypeDescription
positionTypestringType of positioning. Values: 'relative', 'absolute', 'static'.
topnumber/stringDistance from the top edge.
rightnumber/stringDistance from the right edge.
bottomnumber/stringDistance from the bottom edge.
leftnumber/stringDistance from the left edge.

Spacing, Margins and Borders

PropertyTypeDescription
marginnumber/arraySpace outside border box. Can be single value or array for different sides.
paddingnumber/arraySpace inside border box. Can be single value or array for different sides.
bordernumber/arrayBorder width. Can be single value or array for different sides.

Object Fitting and Alignment

PropertyTypeDescription
objectFitstringHow object is resized to fit layout box. Values: 'contain', 'cover', 'fill', 'none', 'scale-down'.
objectPositionstringAnchor point of object inside layout box. E.g. 'center', 'top left'.
transformOriginstringPivot point for rotation and scaling of layout box.

Shadow

PropertyTypeDescription
blurnumberBlur strength.
colornumberColor of the shadow.
offsetobjectOffset of the shadow.
qualitynumberQuality of the shadow.