Class: Sprite

Sprite(xopt, yopt, coloropt, …imageSrcs)

Represents a sprite with image costumes, collision detection, and event handling.

Constructor

new Sprite(xopt, yopt, coloropt, …imageSrcs)

Creates a new Sprite.
Parameters:
Name Type Attributes Default Description
x number <optional>
0 Initial x-coordinate.
y number <optional>
0 Initial y-coordinate.
color string <optional>
'white' The sprite's color.
imageSrcs string <repeatable>
One or more image source URLs for the sprite costumes.
Source:

Extends

Members

hidden :boolean

Type:
  • boolean
Overrides:
Source:

Methods

clearPen()

Clears all pen trails.
Source:

draw()

Draws the sprite on the canvas.
Overrides:
Source:

getCollisionSize() → {Object}

Retrieves the collision size of the sprite.
Source:
Returns:
An object containing width and height.
Type
Object

isClicked(mouseX, mouseY) → {boolean}

Checks if the sprite is clicked based on mouse coordinates.
Parameters:
Name Type Description
mouseX number The x-coordinate of the mouse.
mouseY number The y-coordinate of the mouse.
Source:
Returns:
True if clicked; otherwise, false.
Type
boolean

isHovered(mx, my) → {boolean}

Checks if the sprite is hovered by the mouse.
Parameters:
Name Type Description
mx number Mouse x-coordinate.
my number Mouse y-coordinate.
Source:
Returns:
True if hovered; otherwise, false.
Type
boolean

isOnGround() → {boolean}

Determines if the sprite is on the ground.
Source:
Returns:
True if on ground; otherwise, false.
Type
boolean

isTouching(other) → {boolean}

Checks if this sprite is touching another sprite.
Parameters:
Name Type Description
other Sprite The other sprite to check against.
Source:
Returns:
True if touching; otherwise, false.
Type
boolean

on(eventName, callback)

Registers an event callback for the sprite.
Parameters:
Name Type Description
eventName string Name of the event.
callback function Callback function to invoke.
Source:

onTouch(target, callback)

Registers a continuous touch event callback.
Parameters:
Name Type Description
target Sprite The target sprite to detect touch with.
callback function Function to call when touching the target.
Source:

onTouchEnd(target, callback)

Registers a callback for when the sprite stops touching a target.
Parameters:
Name Type Description
target Sprite The target sprite.
callback function Function to call when touch ends.
Source:

onTouchOnce(target, callback)

Registers a one-time touch event callback.
Parameters:
Name Type Description
target Sprite The target sprite.
callback function Function to call once when touching the target.
Source:

setControlScheme(scheme)

Sets the control scheme for the sprite.
Parameters:
Name Type Description
scheme Object An object mapping controls (e.g., left, right, up, down).
Source:

setCostume(index)

Sets the sprite's costume.
Parameters:
Name Type Description
index number The index of the costume to display.
Source:

startDrawing()

Starts drawing a pen trail.
Source:

stopDrawing()

Stops drawing a pen trail.
Source:

trigger(eventName, eventObject)

Triggers an event.
Parameters:
Name Type Description
eventName string Name of the event.
eventObject * Data associated with the event.
Source:

update()

Updates the sprite. Override to define custom update behavior.
Source: