Module components_sprite
Component that renders an image or colored rectangle in world space.
Info:
- Author: Sharper Dev
Functions
| Sprite:new (gameObject) | Creates an enabled sprite component with a white tint. |
| Sprite:setScreen (screen) | Registers this sprite's render task on the given screen in world space. |
| Sprite:setColor (r, g, b, a) | Sets the sprite tint; alpha defaults to 255 when omitted. |
| Sprite:setSprite (imgPath) | Loads the sprite image and updates the component's dimensions. |
| Sprite:destroy () | Releases the sprite image and unregisters its render task on scene switch. |
| Sprite:render () | Draws the sprite or its colored placeholder when invoked by the renderer. |
Functions
- Sprite:new (gameObject)
-
Creates an enabled sprite component with a white tint.
Parameters:
- gameObject table Game object that owns this component.
Returns:
-
table The new Sprite component.
- Sprite:setScreen (screen)
-
Registers this sprite's render task on the given screen in world space.
Parameters:
- screen number Screen on which to render the sprite.
Returns:
-
table This sprite component.
Usage:
sprite:setScreen(TOP_SCREEN) - Sprite:setColor (r, g, b, a)
-
Sets the sprite tint; alpha defaults to 255 when omitted.
Parameters:
- r number Red color channel.
- g number Green color channel.
- b number Blue color channel.
- a number|nil Alpha channel, defaulting to 255.
Returns:
-
table This sprite component.
Usage:
sprite:setColor(255, 0, 0)
- Sprite:setSprite (imgPath)
-
Loads the sprite image and updates the component's dimensions.
Parameters:
- imgPath string Path or bank ID accepted by the image bank.
Returns:
-
table This sprite component.
Usage:
sprite:setSprite("sprites/player.png")
- Sprite:destroy ()
- Releases the sprite image and unregisters its render task on scene switch.
- Sprite:render ()
- Draws the sprite or its colored placeholder when invoked by the renderer.