Class: Animation

Animation

new Animation()

An animated picture made of multiple images. Animations are constructed for you by AnimationLoader.
Source:

Members

frame :number

The currently displayed frame of the Animation.
Type:
  • number
Source:

(readonly) height :number

The height of the first frame of the Animation.
Type:
  • number
Source:

repeatAt :number

The frame at which to restart the Animation after the last frame plays. It defaults to 0, so animations loop. If you want to disable looping, set this to the last frame. Otherwise, you can set it to one of the middle frames to have non-repeating introductory frames, while having looping later frames.
Type:
  • number
Source:

(readonly) width :number

The width of the first frame of the Animation.
Type:
  • number
Source:

Methods

add(img, time)

Add a frame to the Animation.
Parameters:
Name Type Description
img external:canvas | external:image The image to draw for the frame being added.
time number How long, in milliseconds, this frame should be displayed in the Animation.
Source:

copy() → {Animation}

Make a copy of this Animation.
Source:
Returns:
Type
Animation

draw(context, x, y)

Draw the current frame of the Animation.
Parameters:
Name Type Description
context external:CanvasRenderingContext2D The drawing context.
x number The x coordinate to draw the animation at.
y number The y coordinate to draw the animation at.
Source:

flipHorizontally() → {Animation}

Flip all frames in the Animation horizontally. Useful when you want to use a single set of images for left and right animations.
Source:
Returns:
The Animation, so you can chain calls to rotate/flip methods.
Type
Animation

flipVertically() → {Animation}

Flip all frames in the Animation vertically. Useful when you want to use a single set of images for up and down animations.
Source:
Returns:
The Animation, so you can chain calls to rotate/flip methods.
Type
Animation

move(elapsedMillis)

Advance the Animation by a number of milliseconds.
Parameters:
Name Type Description
elapsedMillis number How many milliseconds to advance the animation by.
Source:

reset()

Reset the Animation to the first frame. This can be useful when you have one piece of code calling Animation#move each frame, but you want the animation to appear stopped.
Source:

rotateClockwise() → {Animation}

Rotate all frames in the Animation clockwise by 90 degrees.
Source:
Returns:
The Animation, so you can chain calls to rotate/flip methods.
Type
Animation

rotateCounterclockwise() → {Animation}

Rotate all frames in the Animation counter-clockwise by 90 degrees.
Source:
Returns:
The Animation, so you can chain calls to rotate/flip methods.
Type
Animation

step()

Advance the Animation by a single frame.
Source: