Constructors

- Animation

Constructor Summary

Animation
(image,
numCellsX,
numCellsY,
speed,
looping,
startFrame,
endFrame,
autoResize,
offset)
An Animation object is used in WADE to store and update animation data.

Functions Summary

clone()
Clone the animation
Get the number of frames in the animation
Get the current frame number
Get the size of a single animation frame
Get the area of the source image (expressed as a fraction of the source image size) that is being used to draw this animation.
Get the name of the image being used.
Get the size of the image (i.e.
Get the number of cells in the animation spritesheet
Get the world-space offset of this animation relative to its parent sprite
Get the name of the image being used.
Get the current animation speed
Check whether the animation is playing
play
(direction)
Play the animation
resume()
Resume an animation that had previously been stopped
serialize
(stringify,
propertiesToExclude)
Export this animation to an object that can then be used to create a new animation like this one (by passing the resulting object to the Animation constructor).
setBlending
(toggle)
Enable or disable blending between animation frames.
setFrameNumber
(frameNumber)
Set the current animation frame
setImageArea
(minX,
minY,
maxX,
maxY)
Set the area of the source image that should be used to draw this animation.
setOffset
(offset)
Set an offset for this animation.
setSpeed
(speed)
Set the current animation speed
step()
Perform a simulation step for the current animation.
stop()
Stop the animation

Constructor Details


(image,
numCellsX,
numCellsY,
speed,
looping,
startFrame,
endFrame,
autoResize,
offset)
An Animation object is used in WADE to store and update animation data. It has a reference to an image that contains one or more frames of animation. It is assumed that all frames have the same size, and that the image size is an integer multiple of the frame size.

Parameters:


{string|object}imageOptional
A file name of an image that has previously been loaded. If omitted or falsy, a blank image will be used. You can also use this constructor by passing in a single object (so just the first parameter) that contains all the animation properties that you want to set (see remarks below for more details).
{number}numCellsXOptional, Default: 1
The number of horizontal cells in the image
{number}numCellsYOptional, Default: 1
The number of vertical cells in the image
{number}speedOptional, Default: 20
The animation speed, in frames per second
{boolean}loopingOptional, Default: false
Whether the animation should start again automatically when it's finished playing
{number}startFrameOptional, Default: 0
The cell index corresponding to the first frame in the animation
{number}endFrameOptional
The cell index corresponding to the last frame in the animation. If omitted or falsy, the last cell index will be used.
{boolean}autoResizeOptional
Whether the animation, when played, should automatically preserve the parent sprite's scale factor.
{{x:number|y:number}}offsetOptional
An object with x and y fields describing an offset (in world space units) to be added to the parent sprite's position when the animation is playing.

Remarks:
You can also use this constructor by passing in a single object (so just the first parameter) that contains all the animation properties that you want to set. In this case, the object structure is as follows (all fields are optional):
 {
     type: 'Animation',
     name: string,
     startFrame: number,
     endFrame: number,
     numCells: {x: number, y: number},
     image: string,
     imageArea: {minX: number, minY: number, maxX: number, maxY: number}
     speed: number,
     looping: boolean,
     stopped: boolean,
     blending: boolean,
     playMode: string,  // 'forward', 'reverse' or 'ping-pong'
     autoResize: boolean,
     offset: {x: number, y: number},
     properties: {}
 };
 
Where properties is a set of properties to copy into the new animation object. Note that properties are deep-copied, and cannot contain functions or cyclical references.

Function Details

()
Clone the animation

Returns:


{object}
A copy of the animation
()
Get the number of frames in the animation

()
Get the current frame number

Returns:


{number}
the current animation frame
()
Get the size of a single animation frame

Returns:


{{x: number|y: number}}
An object with 'x' and 'y' fields representing the size
()
Get the area of the source image (expressed as a fraction of the source image size) that is being used to draw this animation. If this wasn't modified with setImageArea(), by default the animation uses the full image from (0, 0) to (1, 1).

Returns:


{{minX: number|minY: number|maxX: number|maxY: number}}
()
Get the name of the image being used. This returns the full path and file name, including the basePath if a basePath was set. For a relative path, use Animation.getRelativeImageName()

Returns:


{string}
The name of the image being used
()
Get the size of the image (i.e. the whole sprite sheet) being used for the animation

Returns:


{{x: number|y: number}}
An object with 'x' and 'y' fields representing the size
()
Get the number of cells in the animation spritesheet

Returns:


{{x: number|y: number}}
The number of cells in the spritesheet
()
Get the world-space offset of this animation relative to its parent sprite

Returns:


{{x: number|y: number}}
()
Get the name of the image being used. This returns the relative file name, NOT including the basePath even if a basePath was set. For an absolute path, use Animation.getImageName()

Returns:


{string}
The name of the image being used
()
Get the current animation speed

Returns:


{number}
The current animation speed in frames per second
()
Check whether the animation is playing

Returns:


{boolean}
Whether the animation is currently playing

(direction)
Play the animation

Parameters:


{string}directionOptional
The direction of the animation. It can be 'forward', 'reverse' or 'ping-pong' (which means forward and then reverse). Default is 'forward'
()
Resume an animation that had previously been stopped


(stringify,
propertiesToExclude)
Export this animation to an object that can then be used to create a new animation like this one (by passing the resulting object to the Animation constructor).

Parameters:


{boolean}stringifyOptional
Whether the resulting object should be serialized to JSON. If this is set to true, this function returns a string representation of the animation.
{Array}propertiesToExcludeOptional
An array of strings that contains the name of the properties of this Animation object that you do NOT want to export.

Returns:


{object|string}
An object that represents the current animation

(toggle)
Enable or disable blending between animation frames. This is false by default.

Parameters:


{boolean}toggleOptional
Whether or not to enable animation blending. If omitted, 'true' is assumed

(frameNumber)
Set the current animation frame

Parameters:


{number}frameNumber

(minX,
minY,
maxX,
maxY)
Set the area of the source image that should be used to draw this animation. Numbers should be between 0 and 1, representing a fraction of the source image size.

Parameters:


{number}minX
The X coordinate of the left edge. Default is 0.
{number}minY
The Y coordinates of the top edge. Default is 0.
{number}maxX
The X coordinate of the right edge. Default is 1.
{number}maxY
The Y coordinate of the bottom edge. Default is 1.

(offset)
Set an offset for this animation. The parent sprite will be moved by this offset when this animation is playing

Parameters:


offset

(speed)
Set the current animation speed

Parameters:


{number}speed
The animation speed in frames per second
()
Perform a simulation step for the current animation. This may result in displaying a different frame, and/or firing an 'onAnimationEnd' event.
This function is called automatically by WADE at each simulation step (only for animations that are currently playing)

()
Stop the animation