Appearance
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
Parameter | Type | Description |
---|---|---|
id | string | Unique identifier for the spritesheet |
image | string | Path to the spritesheet image |
width | number | Total width of the spritesheet image |
height | number | Total height of the spritesheet image |
framesWidth | number | Number of frames horizontally in the spritesheet |
framesHeight | number | Number of frames vertically in the spritesheet |
rectWidth | number | (Optional) Width of each frame if not equal to width/framesWidth |
rectHeight | number | (Optional) Height of each frame if not equal to height/framesHeight |
offset | { x: number, y: number } | (Optional) Offset to start frame cutting from |
sound | string | (Optional) Path to sound file that plays when animation starts |
spriteRealSize | number | { 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 |
opacity | number | (Optional) Opacity value (0-1) |
textures | object | Contains named animations and their frame definitions |
Animation Frame Parameters
Each frame in an animation can have these properties:
Parameter | Type | Description |
---|---|---|
time | number | Time (in frames) when this frame should be displayed |
frameX | number | Horizontal frame index in the spritesheet |
frameY | number | Vertical frame index in the spritesheet |
x | number | (Optional) X position offset for this frame |
y | number | (Optional) Y position offset for this frame |
angle | number | (Optional) Rotation angle for this frame |
rotation | number | (Optional) Alternative rotation value |
visible | boolean | (Optional) Whether the frame is visible |
opacity | number | (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 |
sound | string | (Optional) Sound to play when this frame is reached |
Sprite Props
Prop | Type | Description |
---|---|---|
image | string | Path to the image (when not using a spritesheet) |
rectangle | { x, y, width, height } | (Optional) Extract only part of the image |
sheet | object | Spritesheet configuration |
sheet.definition | object | The spritesheet definition object |
sheet.playing | string | Name of the animation to play |
sheet.params | object | Parameters passed to the animation function |
sheet.onFinish | function | Callback when animation completes |
loader | object | Loading configuration |
loader.onProgress | function | Progress callback for loading |
loader.onComplete | function | Completion callback for loading |
scaleMode | number | PIXI.js scale mode for the texture |
Common Properties
Property | Type | Description |
---|---|---|
x | number | X-coordinate position of the display object. |
y | number | Y-coordinate position of the display object. |
width | number | Width of the display object. |
height | number | Height of the display object. |
scale | object | Scale of the display object. |
anchor | object | Anchor point of the display object. |
skew | object | Skew of the display object. |
tint | number | Tint color of the display object. |
rotation | number | Rotation of the display object in radians. |
angle | number | Rotation of the display object in degrees. |
zIndex | number | Z-index of the display object. |
roundPixels | boolean | Whether to round pixel values. |
cursor | string | Cursor style when hovering over the display object. |
visible | boolean | Visibility of the display object. |
alpha | number | Alpha transparency of the display object. |
pivot | object | Pivot point of the display object. |
filters | array | Filters applied to the display object. |
maskOf | Element | Element that this display object masks. |
blendMode | string | Blend mode for rendering. |
filterArea | object | Filter 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
Property | Type | Description |
---|---|---|
width | number/string | Width of the display object. Accepts pixels or percentage (e.g. '50%'). |
height | number/string | Height of the display object. Accepts pixels or percentage (e.g. '50%'). |
minWidth | number/string | Minimum width the object can shrink to. |
minHeight | number/string | Minimum height the object can shrink to. |
maxWidth | number/string | Maximum width the object can expand to. |
maxHeight | number/string | Maximum height the object can expand to. |
aspectRatio | number | Ratio between width and height (e.g. 1.5 for 3:2 ratio). |
Flex Layout
Property | Type | Description |
---|---|---|
flexDirection | string | Direction of flex items. Values: 'row', 'column', 'row-reverse', 'column-reverse'. |
flexWrap | string | Whether items wrap. Values: 'wrap', 'nowrap', 'wrap-reverse'. |
justifyContent | string | Alignment along main axis. Values: 'flex-start', 'flex-end', 'center', 'space-between', 'space-around'. |
alignItems | string | Alignment along cross axis. Values: 'flex-start', 'flex-end', 'center', 'stretch', 'baseline'. |
alignContent | string | Alignment of lines with multiple items. Values: 'flex-start', 'flex-end', 'center', 'stretch', 'space-between', 'space-around'. |
alignSelf | string | Override of parent's alignItems for specific item. |
flexGrow | number | Grow factor of item relative to other items. |
flexShrink | number | Shrink factor of item relative to other items. |
flexBasis | number/string | Initial size of item before flex growing/shrinking. |
gap | number/object | Gap between items. |
rowGap | number | Gap between rows. |
columnGap | number | Gap between columns. |
Positioning
Property | Type | Description |
---|---|---|
positionType | string | Type of positioning. Values: 'relative', 'absolute', 'static'. |
top | number/string | Distance from the top edge. |
right | number/string | Distance from the right edge. |
bottom | number/string | Distance from the bottom edge. |
left | number/string | Distance from the left edge. |
Spacing, Margins and Borders
Property | Type | Description |
---|---|---|
margin | number/array | Space outside border box. Can be single value or array for different sides. |
padding | number/array | Space inside border box. Can be single value or array for different sides. |
border | number/array | Border width. Can be single value or array for different sides. |
Object Fitting and Alignment
Property | Type | Description |
---|---|---|
objectFit | string | How object is resized to fit layout box. Values: 'contain', 'cover', 'fill', 'none', 'scale-down'. |
objectPosition | string | Anchor point of object inside layout box. E.g. 'center', 'top left'. |
transformOrigin | string | Pivot point for rotation and scaling of layout box. |
Shadow
Property | Type | Description |
---|---|---|
blur | number | Blur strength. |
color | number | Color of the shadow. |
offset | object | Offset of the shadow. |
quality | number | Quality of the shadow. |