new Sprite()
Represents a visual object that can be drawn on the canvas.
It can render an entire image or a specific rectangular portion of an image (a frame from a sprite sheet).
- Source:
Members
anchor :Object
- Anchor point for rotation and scaling (0-1 scale, e.g., {x:0.5, y:0.5} is center).
Type:
- Object
- Source:
opacity :number
- Opacity of the sprite (0 = transparent, 1 = opaque).
Type:
- number
- Source:
rotation :number
- Rotation angle in radians. Rotation is around the sprite's anchor point.
Type:
- number
- Source:
scaleX :number
- Horizontal scale factor.
Type:
- number
- Source:
scaleY :number
- Vertical scale factor.
Type:
- number
- Source:
visible :boolean
- Whether the sprite should be rendered.
Type:
- boolean
- Source:
Methods
render(context)
Renders the sprite on the canvas context.
Takes into account visibility, opacity, rotation, and scaling.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasRenderingContext2D | The 2D rendering context of the canvas. |
- Source:
setFrame(sx, sy, sWidth, sHeight)
Sets the source frame for the sprite, useful for sprite sheet animations.
Parameters:
Name | Type | Description |
---|---|---|
sx |
number | The x-coordinate of the top-left corner of the frame in the source image. |
sy |
number | The y-coordinate of the top-left corner of the frame in the source image. |
sWidth |
number | The width of the frame in the source image. |
sHeight |
number | The height of the frame in the source image. |
- Source:
update(deltaTime)
Updates the sprite's state. Placeholder for now, could be used for animations internal to the sprite.
Parameters:
Name | Type | Description |
---|---|---|
deltaTime |
number | The time elapsed since the last frame, in seconds. |
- Source: