Constructors

Animation

Constructor Summary

Animation

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.

Fields Summary

Functions Summary

Animation.clone ()

Clone the animation
Animation.getFrameCount ()

Get the number of frames in the animation
Animation.getFrameNumber ()

Get the current frame number
Animation.getFrameSize ()

Get the size of a single animation frame
Animation.getImageArea ()

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).
Animation.getImageName ()

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()
Animation.getImageSize ()

Get the size of the image (i.e. the whole sprite sheet) being used for the animation
Animation.getNumCells ()

Get the number of cells in the animation spritesheet
Animation.getOffset ()

Get the world-space offset of this animation relative to its parent sprite
Animation.getRelativeImageName ()

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()
Animation.getSpeed ()

Get the current animation speed
Animation.isPlaying ()

Check whether the animation is playing
Animation.play (direction)

Play the animation
Animation.resume ()

Resume an animation that had previously been stopped
Animation.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).
Animation.setFrameNumber (frameNumber)

Set the current animation frame
Animation.setImageArea (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.
Animation.setOffset (offset)

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

Set the current animation speed
Animation.step ()

Perform a simulation step for the current animation. This may result in displaying a different frame, and/or firing an 'onAnimationEnd' event.
Animation.stop ()

Stop the animation

Constructor Details

Animation

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.


string|object image (optional): 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 numCellsX (optional, defaults to 1): The number of horizontal cells in the image


number numCellsY (optional, defaults to 1): The number of vertical cells in the image


number [speed : = 20] The animation speed, in frames per second


boolean [looping : = false] Whether the animation should start again automatically when it's finished playing


number [startFrame : = 0] The cell index corresponding to the first frame in the animation


number endFrame (optional): The cell index corresponding to the last frame in the animation. If omitted or falsy, the last cell index will be used.


boolean autoResize (optional): Whether the animation, when played, should automatically preserve the parent sprite's scale factor.


{x:number, y:number} offset (optional): 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,
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.
^

Fields Details

Function Details

Animation.clone ()

Clone the animation

Returns object : A copy of the animation

^
Animation.getFrameCount ()

Get the number of frames in the animation
^
Animation.getFrameNumber ()

Get the current frame number

Returns number : the current animation frame

^
Animation.getFrameSize ()

Get the size of a single animation frame

Returns {x: number, y: number} : An object with 'x' and 'y' fields representing the size

^
Animation.getImageArea ()

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}}

^
Animation.getImageName ()

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

^
Animation.getImageSize ()

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

^
Animation.getNumCells ()

Get the number of cells in the animation spritesheet

Returns {x: number, y: number} : The number of cells in the spritesheet

^
Animation.getOffset ()

Get the world-space offset of this animation relative to its parent sprite

Returns : {{x: number, y: number}}

^
Animation.getRelativeImageName ()

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

^
Animation.getSpeed ()

Get the current animation speed

Returns number : The current animation speed in frames per second

^
Animation.isPlaying ()

Check whether the animation is playing

Returns boolean : Whether the animation is currently playing

^
Animation.play (direction)

Play the animation

string direction (optional): The direction of the animation. It can be 'forward', 'reverse' or 'ping-pong' (which means forward and then reverse). Default is 'forward'

^
Animation.resume ()

Resume an animation that had previously been stopped
^
Animation.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).

boolean stringify (optional): 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 propertiesToExclude (optional): 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

^
Animation.setFrameNumber (frameNumber)

Set the current animation frame
@param {number} frameNumber
^
Animation.setImageArea (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.

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.

^
Animation.setOffset (offset)

Set an offset for this animation. The parent sprite will be moved by this offset when this animation is playing
@param offset
^
Animation.setSpeed (speed)

Set the current animation speed

number speed : The animation speed in frames per second

^
Animation.step ()

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)
^
Animation.stop ()

Stop the animation
^