PIXI.AnimatedSprite

class AnimatedSprite extends PIXI.Sprite

An AnimatedSprite is a simple way to display an animation depicted by a list of textures.

let alienImages = ["image_sequence_01.png","image_sequence_02.png","image_sequence_03.png","image_sequence_04.png"];
let textureArray = [];

for (let i=0; i < 4; i++)
{
     let texture = PIXI.Texture.from(alienImages[i]);
     textureArray.push(texture);
};

let animatedSprite = new PIXI.AnimatedSprite(textureArray);

The more efficient and simpler way to create an animated sprite is using a PIXI.Spritesheet containing the animation definitions:

PIXI.Loader.shared.add("assets/spritesheet.json").load(setup);

function setup() {
  let sheet = PIXI.Loader.shared.resources["assets/spritesheet.json"].spritesheet;
  animatedSprite = new PIXI.AnimatedSprite(sheet.animations["image_sequence"]);
  ...
}

Constructor


new PIXI.AnimatedSprite(textures: PIXI.Texture[] | PIXI.AnimatedSprite.FrameObject[], autoUpdate: boolean) → {}
Parameters:
Name Type Attributes Default Description
textures PIXI.Texture[] | PIXI.AnimatedSprite.FrameObject[]

An array of PIXI.Texture or frame objects that make up the animation.

autoUpdate boolean

<optional>

true

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

Summary


Properties from AnimatedSprite

number
animationSpeed = 1
boolean
autoUpdate

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

number
currentFrame
boolean
loop = true
() => void
onComplete
(currentFrame: number) => void
onFrameChange
() => void
onLoop
boolean
playing
PIXI.Texture[] | PIXI.AnimatedSprite.FrameObject[]
textures

The array of textures used for this AnimatedSprite.

number
totalFrames = 0
boolean
updateAnchor = false

Update anchor to Texture's defaultAnchor when frame changes.

Properties inherited from Sprite

PIXI.ObservablePoint
anchor
PIXI.BLEND_MODES
blendMode = PIXI.BLEND_MODES.NORMAL
number
height

The height of the sprite, setting this will actually modify the scale to achieve the value set.

boolean
isSprite = true
string
pluginName = 'batch'
boolean
roundPixels = false

If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.

PIXI.Texture
texture

The texture that the sprite is using.

number
tint = 0xFFFFFF

The tint applied to the sprite. This is a hex value.

number
width

The width of the sprite, setting this will actually modify the scale to achieve the value set.

PIXI.ObservablePoint
protected _anchor = `this.texture.defaultAnchor`
number
protected _cachedTint = 0xFFFFFF
number
protected _height
HTMLCanvasElement
protected _tintedCanvas = undefined
number
protected _width
Float32Array
protected uvs
Float32Array
protected vertexData

Properties inherited from Container

T[]
children
boolean
interactiveChildren = true
boolean
sortableChildren
boolean
sortDirty

Should children be sorted by zIndex at the next updateTransform call.

Properties inherited from DisplayObject

boolean
_accessibleActive = false
boolean
_accessibleDiv = undefined
PIXI.Bounds
_bounds

The bounds object, this is used to calculate and store the bounds of the displayObject.

PIXI.Bounds
_localBounds

Local bounds object, swapped with _bounds when using getLocalBounds().

boolean
accessible = false
boolean
accessibleChildren = true
string
accessibleHint = undefined
string
accessiblePointerEvents = 'auto'
?string
accessibleTitle = undefined
string
accessibleType = 'button'
number
alpha

The opacity of the object.

number
angle
boolean
buttonMode
boolean
cacheAsBitmap
number
cacheAsBitmapMultisample = PIXI.MSAA_QUALITY.NONE
number
cacheAsBitmapResolution = null
boolean
cullable

Should this object be rendered if the bounds of this object are out of frame?

PIXI.Rectangle
cullArea
string
cursor = undefined
boolean
destroyed

Readonly flag for destroyed display objects.

PIXI.Rectangle
filterArea
PIXI.Filter[] | null
filters
PIXI.IHitArea
hitArea = undefined
boolean
interactive = false
boolean
isMask

Does any other displayObject use this object as a mask?

PIXI.Matrix
localTransform
PIXI.Container | PIXI.MaskData | null
mask
string
name = undefined
PIXI.Container
parent

The display object container that contains this display object.

PIXI.ObservablePoint
pivot
PIXI.ObservablePoint
position
boolean
renderable
number
rotation
PIXI.ObservablePoint
scale

The scale factors of this object along the local coordinate axes.

PIXI.ObservablePoint
skew
PIXI.DisplayObject
smartMask = undefined
PIXI.Transform
transform
boolean
visible
number
worldAlpha
PIXI.Matrix
worldTransform
boolean
worldVisible
number
x
number
y
number
zIndex

The zIndex of the displayObject.

number
protected _boundsID

Flags the cached bounds as dirty.

PIXI.Rectangle
protected _boundsRect

Cache of this display-object's bounds-rectangle.

boolean
protected _destroyed

If the object has been destroyed via destroy(). If true, it should not be used.

PIXI.Filter[]
protected _enabledFilters
number
protected _lastSortedIndex
PIXI.Rectangle
protected _localBoundsRect

Cache of this display-object's local-bounds rectangle.

PIXI.Container | PIXI.MaskData
protected _mask
PIXI.Container
protected _tempDisplayObjectParent
number
protected _zIndex

Methods inherited from Sprite

void
calculateTrimmedVertices()

Calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData.

void
calculateVertices()

Calculates worldTransform * vertices, store it in vertexData.

boolean
containsPoint(point: IPointData)
PIXI.Rectangle
getLocalBounds(rect: PIXI.Rectangle)
void
protected _calculateBounds()

Updates the bounds of the sprite.

void
protected _onTextureUpdate()

When the texture is updated, this event will fire to update the scale and frame.

void
protected _render(renderer: PIXI.Renderer)

Methods inherited from Container

Inherited Events from Container

Inherited Events from DisplayObject

added
childRemoved
click
clickcapture

Capture phase equivalent of click.

destroyed
mousedown
mousedowncapture

Capture phase equivalent of mousedown.

mouseenter

Fired when the mouse pointer is moved over a DisplayObject and its descendant's hit testing boundaries.

mouseentercapture

Capture phase equivalent of mouseenter

mouseleave

Fired when the mouse pointer exits a DisplayObject and its descendants.

mouseleavecapture

Capture phase equivalent of mouseleave.

mousemove
mousemovecature

Capture phase equivalent of mousemove.

mouseout
mouseoutcapture

Capture phase equivalent of mouseout.

mouseover
mouseovercapture

Capture phase equivalent of mouseover.

mouseup
mouseupcature

Capture phase equivalent of mouseup.

mouseupoutside
mouseupoutsidecapture

Capture phase equivalent of mouseupoutside.

pointercancel
pointercancelcapture

Capture phase equivalent of pointercancel.

pointerdown
pointerdowncapture

Capture phase equivalent of pointerdown.

pointerenter

Fired when the pointer is moved over a DisplayObject and its descendant's hit testing boundaries.

pointerentercapture

Capture phase equivalent of pointerenter

pointerleave

Fired when the pointer leaves the hit testing boundaries of a DisplayObject and its descendants.

pointerleavecapture

Capture phase equivalent of pointerleave.

pointermove
pointermovecapture

Capture phase equivalent of pointermove.

pointerout
pointeroutcapture

Capture phase equivalent of pointerout.

pointerover
pointerovercapture

Capture phase equivalent of pointerover.

pointertap
pointertapcapture

Capture phase equivalent of pointertap.

pointerup
pointerupcapture

Capture phase equivalent of pointerup.

pointerupoutside
pointerupoutsidecapture

Capture phase equivalent of pointerupoutside.

removed
rightclick
rightclickcapture

Capture phase equivalent of rightclick.

rightdown
rightdowncapture

Capture phase equivalent of rightdown.

rightup
rightupcapture

Capture phase equivalent of rightup.

rightupoutside
rightupoutsidecapture

Capture phase equivalent of rightupoutside.

tap
tapcapture

Capture phase equivalent of tap.

touchcancel
touchcancelcapture

Capture phase equivalent of touchcancel.

touchend
touchendcapture

Capture phase equivalent of touchend.

touchendoutside
touchendoutsidecapture

Capture phase equivalent of touchendoutside.

touchmove
touchmovecapture

Capture phase equivalent of touchmove.

touchstart
touchstartcapture

Capture phase equivalent of touchstart.

PIXI.FederatedWheelEvent
wheel

Fired when a the user scrolls with the mouse cursor over a DisplayObject.

PIXI.FederatedWheelEvent
wheelcapture

Capture phase equivalent of wheel.

Public Properties


animationSpeed AnimatedSprite.ts:38
animationSpeed: number = 1

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

autoUpdate AnimatedSprite.ts:435
autoUpdate: boolean

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

currentFrame AnimatedSprite.ts:410
currentFrame: number

The AnimatedSprites current frame index.

loop AnimatedSprite.ts:44
loop: boolean = true

Whether or not the animate sprite repeats after playing.

onComplete AnimatedSprite.ts:62
onComplete: () => void

User-assigned function to call when an AnimatedSprite finishes playing.


 animation.onComplete = function () {
   // finished!
 };
onFrameChange AnimatedSprite.ts:71
onFrameChange: (currentFrame: number) => void

User-assigned function to call when an AnimatedSprite changes which texture is being rendered.


 animation.onFrameChange = function () {
   // updated!
 };
onLoop AnimatedSprite.ts:80
onLoop: () => void

User-assigned function to call when loop is true, and an AnimatedSprite is played and loops around to start again.


 animation.onLoop = function () {
   // looped!
 };
playing AnimatedSprite.ts:426
playing: boolean

Indicates if the AnimatedSprite is currently playing.

textures AnimatedSprite.ts:381
textures: PIXI.Texture[] | PIXI.AnimatedSprite.FrameObject[]

The array of textures used for this AnimatedSprite.

totalFrames AnimatedSprite.ts:370
totalFrames: number = 0

The total number of frames in the AnimatedSprite. This is the same as number of textures assigned to the AnimatedSprite.

updateAnchor AnimatedSprite.ts:50
updateAnchor: boolean = false

Update anchor to Texture's defaultAnchor when frame changes.

Useful with sprite sheet animations created with tools. Changing anchor for each frame allows to pin sprite origin to certain moving feature of the frame (e.g. left foot).

Note: Enabling this will override any previously set anchor on each frame change.

Public Methods


fromFrames AnimatedSprite.ts:336
static fromFrames(frames: string[]) → {PIXI.AnimatedSprite}

A short hand way of creating an AnimatedSprite from an array of frame ids.

Parameters:
Name Type Description
frames string[]

The array of frames ids the AnimatedSprite will use as its texture frames.

Returns:
Type Description
PIXI.AnimatedSprite
  • The new animated sprite with the specified frames.
fromImages AnimatedSprite.ts:353
static fromImages(images: string[]) → {PIXI.AnimatedSprite}

A short hand way of creating an AnimatedSprite from an array of image ids.

Parameters:
Name Type Description
images string[]

The array of image urls the AnimatedSprite will use as its texture frames.

Returns:
Type Description
PIXI.AnimatedSprite

The new animate sprite with the specified images as frames.

destroy AnimatedSprite.ts:317
destroy(options: object | boolean) → {void}

Stops the AnimatedSprite and destroys it.

Parameters:
Name Type Attributes Default Description
options object | boolean

<optional>

Options parameter. A boolean will act as if all options have been set to that value.

options.children boolean

<optional>

false

If set to true, all the children will have their destroy method called as well. 'options' will be passed on to those calls.

options.texture boolean

<optional>

false

Should it destroy the current texture of the sprite as well.

options.baseTexture boolean

<optional>

false

Should it destroy the base texture of the sprite as well.

Returns:
Type Description
void
gotoAndPlay AnimatedSprite.ts:191
gotoAndPlay(frameNumber: number) → {void}

Goes to a specific frame and begins playing the AnimatedSprite.

Parameters:
Name Type Description
frameNumber number

Frame index to start at.

Returns:
Type Description
void
gotoAndStop AnimatedSprite.ts:173
gotoAndStop(frameNumber: number) → {void}

Stops the AnimatedSprite and goes to a specific frame.

Parameters:
Name Type Description
frameNumber number

Frame index to stop at.

Returns:
Type Description
void
play AnimatedSprite.ts:157
play() → {void}

Plays the AnimatedSprite.

Returns:
Type Description
void
stop AnimatedSprite.ts:141
stop() → {void}

Stops the AnimatedSprite.

Returns:
Type Description
void
update AnimatedSprite.ts:209
update(deltaTime: number) → {void}

Updates the object transform for rendering.

Parameters:
Name Type Description
deltaTime number

Time since last tick.

Returns:
Type Description
void

Powered by webdoc!