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. |
Extends
Members
hidden :boolean
Type:
- boolean
- Overrides:
- Source:
Methods
clearPen()
Clears all pen trails.
draw()
Draws the sprite on the canvas.
- Overrides:
- Source:
getCollisionSize() → {Object}
Retrieves the collision size of the sprite.
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. |
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. |
Returns:
True if hovered; otherwise, false.
- Type
- boolean
isOnGround() → {boolean}
Determines if the sprite is on the ground.
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. |
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. |
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. |
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. |
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. |
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). |
setCostume(index)
Sets the sprite's costume.
Parameters:
| Name | Type | Description |
|---|---|---|
index | number | The index of the costume to display. |
startDrawing()
Starts drawing a pen trail.
stopDrawing()
Stops drawing a pen trail.
trigger(eventName, eventObject)
Triggers an event.
Parameters:
| Name | Type | Description |
|---|---|---|
eventName | string | Name of the event. |
eventObject | * | Data associated with the event. |
update()
Updates the sprite. Override to define custom update behavior.