Animation
Hierarchy
- Graphic
- Animation
Implements
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
Parameters
options: GraphicOptions & AnimationOptions
Returns Animation
Properties
publicevents
publicframeDuration
publicframes
readonlyid
publicopacity
Gets or sets the opacity of the graphic, 0 is transparent, 1 is solid (opaque).
publicshowDebug
Gets or sets wether to show debug information about the graphic
publicstrategy
publicoptionaltint
publictransform
Accessors
publiccanFinish
Returns
true
if the animation can endReturns boolean
publiccurrentFrame
Returns the current Frame of the animation
Use Animation.currentFrameIndex to get the frame number and Animation.goToFrame to set the current frame index
Returns Frame
publiccurrentFrameIndex
Returns the current frame index of the animation
Use Animation.currentFrame to grab the current Frame object
Returns number
publiccurrentFrameTimeLeft
Returns the amount of time in milliseconds left in the current frame
Returns number
publicdirection
Returns the current play direction of the animation
Returns AnimationDirection
publicdone
Returns
true
if the animation is done, for looping type animationsex.AnimationStrategy.PingPong
andex.AnimationStrategy.Loop
this will always returnfalse
See the
ex.Animation.canFinish()
method to know if an animation type can endReturns boolean
publicflipHorizontal
Gets or sets the flipHorizontal, which will flip the graphic horizontally (across the y axis)
Returns boolean
Parameters
value: boolean
Returns void
publicflipVertical
Gets or sets the flipVertical, which will flip the graphic vertically (across the x axis)
Returns boolean
Parameters
value: boolean
Returns void
publicheight
Gets or sets the height of the graphic (always positive)
Returns number
publicisPlaying
Returns
true
if the animation is playingReturns boolean
publiclocalBounds
Gets a copy of the bounds in pixels occupied by the graphic on the the screen. This includes scale.
Returns BoundingBox
publicorigin
publicrotation
Gets or sets the rotation of the graphic
Returns number
Parameters
value: number
Returns void
publicscale
publicspeed
Current animation speed
1 meaning normal 1x speed. 2 meaning 2x speed and so on.
Returns number
Current animation speed
1 meaning normal 1x speed. 2 meaning 2x speed and so on.
Parameters
val: number
Returns void
publicwidth
Gets or sets the width of the graphic (always positive)
Returns number
Methods
publicclone
Returns a new instance of the graphic that has the same properties
Returns Animation
publiccloneGraphicOptions
Returns GraphicOptions
publicdraw
Draw the whole graphic to the context including transform
Parameters
ex: ExcaliburGraphicsContext
The excalibur graphics context
x: number
y: number
Returns void
publicgoToFrame
Jump the animation immediately to a specific frame if it exists
Optionally specify an override for the duration of the frame, useful for keeping multiple animations in sync with one another.
Parameters
frameNumber: number
optionalduration: number
Returns void
publicisStale
Returns boolean
publicpause
Pauses the animation on the current frame
Returns void
publicplay
Plays or resumes the animation from the current frame
Returns void
publicreset
Reset the animation back to the beginning, including if the animation were done
Returns void
publicreverse
Reverses the play direction of the Animation, this preserves the current frame
Returns void
publictick
Called internally by Excalibur to update the state of the animation potential update the current frame
Parameters
elapsedMilliseconds: number
Milliseconds elapsed
idempotencyToken: number = 0
Prevents double ticking in a frame by passing a unique token to the frame
Returns void
publicstaticfromSpriteSheet
Create an Animation from a SpriteSheet, a list of indices into the sprite sheet, a duration per frame and optional AnimationStrategy
Example:
const spriteSheet = SpriteSheet.fromImageSource({...}); const anim = Animation.fromSpriteSheet(spriteSheet, range(0, 5), 200, AnimationStrategy.Loop);
Parameters
spriteSheet: SpriteSheet
ex.SpriteSheet
spriteSheetIndex: number[]
0 based index from left to right, top down (row major order) of the ex.SpriteSheet
durationPerFrameMs: number
duration per frame in milliseconds
strategy: AnimationStrategy = AnimationStrategy.Loop
Optional strategy, default AnimationStrategy.Loop
Returns Animation
publicstaticfromSpriteSheetCoordinates
Create an Animation from a SpriteSheet given a list of coordinates
Example:
const spriteSheet = SpriteSheet.fromImageSource({...}); const anim = Animation.fromSpriteSheetCoordinates({ spriteSheet, frameCoordinates: [ {x: 0, y: 5, duration: 100, options { flipHorizontal: true }}, {x: 1, y: 5, duration: 200}, {x: 2, y: 5}, {x: 3, y: 5} ], strategy: AnimationStrategy.PingPong });
Parameters
options: FromSpriteSheetOptions
Returns Animation
Animation
Create an Animation given a list of
frames
in AnimationOptionsTo create an Animation from a SpriteSheet, use Animation.fromSpriteSheet