Function: addAnimatedSprite()
Call Signature
> addAnimatedSprite(alias, options?): AnimatedSprite
Defined in: src/canvas/functions/animated-sprite-utility.ts:77
Add an animated sprite in the canvas, using alias as the spritesheet alias. The frames are not loaded: use AnimatedSprite.load.
Parameters
alias
string
The unique alias of the component, also used as the alias of the spritesheet (it must be registered in the asset cache or manifest).
options?
The options of the animated sprite.
Returns
This function returns an AnimatedSprite that you can use to manipulate the component.
Throws
when alias is not registered in the asset cache.
Example
Assets.add({ alias: "fighter", src: "https://pixijs.com/assets/spritesheet/fighter.json" });
const fighter = addAnimatedSprite("fighter", { align: 0.5, animationSpeed: 0.4 });
await fighter.load();Call Signature
> addAnimatedSprite(alias, source?, options?): AnimatedSprite
Defined in: src/canvas/functions/animated-sprite-utility.ts:98
Add an animated sprite in the canvas. Is the same that showAnimatedSprite, but the frames are not loaded. If you want to show the animated sprite, then you need to use the function AnimatedSprite.load.
Parameters
alias
string
The unique alias of the animated sprite. You can use this alias to refer to this component.
source?
string | AnimatedSpriteSource
The frames of the animation: the alias/URL of a spritesheet, or an AnimatedSpriteSource.
If you don't provide it, or it has no spritesheet and no frames (e.g. { animation: "walk" }), the alias is used as the spritesheet alias.
options?
The options of the animated sprite.
Returns
This function returns an AnimatedSprite that you can use to manipulate the component.
Throws
when source is not provided and alias is not registered in the asset cache.
Example
Assets.add({ alias: "fighter", src: "https://pixijs.com/assets/spritesheet/fighter.json" });
// a different alias for the component: (alias, spritesheetAlias, options)
const myFighter = addAnimatedSprite("myFighter", "fighter", { loop: true });
await myFighter.load();
myFighter.play();