Skip to content

AnimatedSprite

A simple way to display an animation depicted by a list of textures.

I recommend using spritesheets created by TexturePacker (they have a great tutorial on it). If you don’t want to use spritesheets, you can simply just pass in an array of your desired textures.

Spritesheet

<script>
import * as PIXI from 'pixi.js'
import { AnimatedSprite, AssetsLoader } from 'svelte-pixi'
</script>
<AssetsLoader assets={['/assets/adventurer-spritesheet.json']}>
<AnimatedSprite
textures={[
PIXI.Texture.from('adventurer-idle-00.png'),
PIXI.Texture.from('adventurer-idle-01.png'),
PIXI.Texture.from('adventurer-idle-02.png'),
]}
playing
animationSpeed={0.1}
anchor={0.5}
scale={3}
/>
</AssetsLoader>

Multiple Animations

<script>
import { AnimatedSprite, AssetsLoader } from 'svelte-pixi'
import { Assets } from 'pixi.js'
// loaded from parent <AssetsLoader />
const spritesheet = Assets.get('/assets/adventurer-spritesheet.json')
let textures = spritesheet.animations['adventurer-idle']
function changeAnimation() {
// pick an an animation from the spritesheet at random
const keys = Object.keys(spritesheet.animations)
const randomIndex = Math.floor(Math.random() * keys.length)
textures = spritesheet.animations[keys[randomIndex]]
}
</script>
<AnimatedSprite
{textures}
playing
animationSpeed={0.1}
anchor={0.5}
scale={3}
on:loop={changeAnimation}
/>

API

Props

NameDescription
anchor
PointLike

The anchor sets the origin point of the text.

animationSpeed
1
number

The speed that the AnimatedSprite will play at. Higher is faster, lower is slower.

autoUpdate
boolean

Whether to use PIXI.Ticker.shared to auto update animation time

blendMode

The blend mode to be applied to the sprite. Apply a value of PIXI.BLEND_MODES.NORMAL to reset the blend mode.

instance
PIXI.AnimatedSprite

The PIXI.AnimatedSprite instance. Can be set or bound to.

loop
true
boolean

Whether or not the animate sprite repeats after playing.

playing
true
boolean

Plays the animation according to the textures

pluginName
string

Plugin that is responsible for rendering this element.

roundPixels
boolean

If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation. Advantages can include sharper image quality (like text) and faster rendering on canvas. The main disadvantage is movement of objects may appear less smooth.

textures
[]
PIXI.Texture<PIXI.Resource>[]PIXI.FrameObject[]

The array of textures to use

Additional props are passed on to Container

Slots

NamePropsFallback
default{}

Events

NameTypeDetail
addedforwarded
clickforwarded
completedispatchednull
createforwarded
frameChangedispatchednull
globalmousemoveforwarded
globalpointermoveforwarded
globaltouchmoveforwarded
loopdispatchednull
mousedownforwarded
mousemoveforwarded
mouseoutforwarded
mouseoverforwarded
mouseupforwarded
mouseupoutsideforwarded
pointercancelforwarded
pointerdownforwarded
pointermoveforwarded
pointeroutforwarded
pointeroverforwarded
pointertapforwarded
pointerupforwarded
pointerupoutsideforwarded
removedforwarded
removedFromforwarded
rightclickforwarded
rightdownforwarded
rightupforwarded
rightupoutsideforwarded
tapforwarded
touchcancelforwarded
touchendforwarded
touchendoutsideforwarded
touchmoveforwarded
touchstartforwarded