Sprite#

Used for drawing images onto the canvas.

Constructor#

new Sprite(image, width, height)#

Create a new sprite.
Parameters:
NameTypeDescription
imageHTMLImageElementImage to use for drawing
widthnumberWidth of image
heightnumberHeight of image

Members#

height#

Get the height of the sprite.

image#

Get the image for the sprite.

width#

Get the width of the sprite.

Methods#

draw(ctx, pos, size)#

Draw the sprite.
Parameters:
NameTypeDefaultDescription
ctxCanvasRenderingContext2D
posVec2Position/offset to draw sprite at
sizeVec2 | nullnullCustom size of drawn sprite (or null to use default)

update(elapsed)#

Update the sprite.
Parameters:
NameTypeDescription
elapsednumberTime since last update cycle in seconds