Class: Sprite

Sprite(config)

new Sprite(config)

Sprite sets up a constructor for a simple game sprite. You can draw your own spritesheet using a tool like https://www.piskelapp.com/
Parameters:
Name Type Description
config Object
Properties
Name Type Description
src string URL of SpriteSheet resource.
x number Position of Sprite on the canvas
y number Position of Sprite on the canvas
frameWidth number width of each frame of the sprite sheet (defaults to width of image)
frameHeight number height of each frame of the sprite sheet (defaults to height of image)
frame number frame to start on (default to 0).
frameSequence Array list of frame indices to run (if not specified, we run all frames in order).
targetWidth number width of sprite to draw on canvas (same as source image if not specified)
targetHeight number height of sprite to draw on canvas (same as source image if not specified)
animate boolean whether to animate or not.
frameRate number Number of frames per second to run animation at.
repeat number Whether to repeat the animation or play only once (true by default)
angle number Angle to rotate drawing (in radians)
update SimpleCanvas.Sprite~updateCallback a callback to run on each animation frame just before drawing sprite to canvas.
Source:

Methods

copy(newParams)

Create a copy of sprite.
Parameters:
Name Type Description
newParams Object settings to override (all other settings will be copied from current sprite) Return a copy of sprite.
Source:

draw()

draw sprite to canvas
Source:

Type Definitions

Sprite

Properties:
Name Type Description
frameSequence Array list of frame indices to run (if not specified, we run all frames in order).
animate boolean whether to run animation or not.
frameRate number frames per second to play animation at.
frameAnimationIndex number current frame (relative to frameSequence). Set to 0 to restart animation
Source:

updateCallback(config)

This callback runs just before sprite is drawn to canvas.
Parameters:
Name Type Description
config Object
Properties
Name Type Description
sprite Object sprite object being updated
width number width of canvas
height number height of canvas
elapsed number milliseconds since first drawing
timestamp number current timestamp
stepTime number milliseconds passed since last tick
remove number a function that will remove this callback from the queue
Source: