Namespace: sprite

animation.sprite

Each "sprite" (sourced from either an image file or drawn) has these common properties needed by drawImage, translate and rotate
Properties:
Name Type Description
image Image any format acceptable to drawImage
loaded boolean guards drawImage from crashing because image isn't loaded
sx pixels the left hand side of the source image, 0 if not taken from a sprite sheet
sy pixels the top side of the source image, 0 if not taken from a sprite sheet
sWidth pixels width of the source image
sHeight pixels height of the source image
dWidth pixels width of the drawn image, modified by screen size
dHeight pixels height of the drawn image, modified by screen size
x1 pixels sprite's current center X, used by ctx.translate
y1 pixels sprite's current center Y, used by ctx.translate
angle1 radians direction in radians the sprite is currently facing, converted to radians for ctx.rotate
x2 pixels sprite's destination center X, same as x1 if not moving
y2 pixels sprite's destination center Y
angle2 radians sprite's destination direction, same as angle1 if it's not rotating
velocity pixels 0.0 if the sprite is stationary
deltaX pixels added to x1 each tick, Math.cos(angle1 in radians) * velocity
deltaY pixels added to y1 each tick, Math.sin(angle1 in radians) * velocity
deltaAngle degrees - added to angle1 each tick, controls how fast sprites
live boolean if false, gets removed from sprites array
base Array the element in state the sprite was created from
attacking Array base of a sprite in the destination cell, otherwise undefined
defending Array base of a sprite moving on to this sprite's cell, othewise undefined
Source: