Constructors
- Animation
- IsoCharacter
- Path
- PhysicsObject
- SceneObject
- SceneObjectGroup
- Sprite
- TextSprite
- TilemapCharacter
- wade
- wade.drawFunctions
- wade.iso
- wade.physics
- wade.tilemap
- wade.vec2
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.
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
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.
numCellsX (optional, defaults to 1): The number of horizontal cells in the image
numCellsY (optional, defaults to 1): The number of vertical cells in the image
speed (defaults to 20): The animation speed, in frames per second
looping (defaults to false): Whether the animation should start again automatically when it's finished playing
startFrame (defaults to 0): The cell index corresponding to the first frame in the animation
endFrame (optional): The cell index corresponding to the last frame in the animation.
autoResize (optional): Whether the animation, when played, should automatically preserve the parent sprite's scale factor.
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.
Function Details
- Animation.clone ()
- Clone the animation
Returns Animation : 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.
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.
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.
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.
Animation.resume ()
- Resume an animation that had previously been stopped.
Animation.serialize (stringify, propertiesToExclude)
- Export this animation to an object to create a new animation.
Animation.setFrameNumber (frameNumber)
- Set the current animation frame.
Animation.setImageArea (minX, minY, maxX, maxY)
- Set the area of the source image for this animation.
Animation.setOffset (offset)
- Set an offset for this animation.
Animation.setSpeed (speed)
- Set the current animation speed.
Animation.step ()
- Perform a simulation step for the current animation.
Animation.stop ()
- Stop the animation.