Classes


Class Animation

Class Summary
Constructor Attributes Constructor Name and Description
 
Animation(image, numCellsX, numCellsY, speed, looping, startFrame, endFrame, autoResize, offset)
An Animation object is used in WADE to store and update animation data.
Method Summary
Method Attributes Method Name and Description
 
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.
 
Check whether the animation is playing
 
play(direction)
Play the animation
 
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.
 
step()
Perform a simulation step for the current animation.
 
stop()
Stop the animation
Class Detail
Animation(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} 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, Default: 1
The number of horizontal cells in the image
{number} numCellsY Optional, Default: 1
The number of vertical cells in the image
{number} speed Optional, Default: 20
The animation speed, in frames per second
{boolean} looping Optional, Default: false
Whether the animation should start again automatically when it's finished playing
{number} startFrame Optional, Default: 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,
     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.
Method Detail
{object} clone()
Clone the animation
Returns:
{object} A copy of the animation

getFrameCount()
Get the number of frames in the animation

{number} getFrameNumber()
Get the current frame number
Returns:
{number} the current animation frame

{{x: number|y: number}} getFrameSize()
Get the size of a single animation frame
Returns:
{{x: number|y: number}} An object with 'x' and 'y' fields representing the size

{{minX: number|minY: number|maxX: number|maxY: number}} 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}}

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

{{x: number|y: number}} 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

{{x: number|y: number}} getNumCells()
Get the number of cells in the animation spritesheet
Returns:
{{x: number|y: number}} The number of cells in the spritesheet

{{x: number|y: number}} getOffset()
Get the world-space offset of this animation relative to its parent sprite
Returns:
{{x: number|y: number}}

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

{boolean} isPlaying()
Check whether the animation is playing
Returns:
{boolean} Whether the animation is currently playing

play(direction)
Play the animation
Parameters:
{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'

resume()
Resume an animation that had previously been stopped

{object|string} 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).
Parameters:
{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

setBlending(toggle)
Enable or disable blending between animation frames. This is false by default.
Parameters:
{boolean} toggle Optional
Whether or not to enable animation blending. If omitted, 'true' is assumed

setFrameNumber(frameNumber)
Set the current animation frame
Parameters:
{number} frameNumber

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

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

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)

stop()
Stop the animation

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Jul 12 2016 07:54:40 GMT+0100 (BST)