class Sprite (client-side)
Available since version: 0.3.0
This class represents a 2d Sprite on screen.
Constructor
Sprite.new(number x, number y, number width, number height, string file)
Parameters:
numberx: X position (virtual units).numbery: Y position (virtual units).numberwidth: Width (virtual units).numberheight: Height (virtual units).stringfile: Texture file path displayed by the sprite.
Properties
{x, y} position
Represents the Sprite position in virtual screen units.
{x, y} positionPx
Represents the Sprite position in pixel coordinates.
{width, height} size
Represents the Sprite size in virtual screen units.
{width, height} sizePx
Represents the Sprite size in pixel coordinates.
{r, g, b, a} color
Represents the Sprite color.
number alpha
Opacity from 0 (transparent) to 255 (opaque).
string file
Represents the texture file path.
boolean visible
Represents whether the texture is rendered.
table uvRect
Normalized texture rectangle {x, y, width, height}, independent of screen position and size.
Methods
setPosition
This method will set the Sprite position in virtual screen units.
void setPosition(number x, number y)
Parameters:
numberx: X position (virtual units).numbery: Y position (virtual units).
getPosition
This method will return the Sprite position in virtual screen units.
{x, y} getPosition()
Returns {x, y}:
Table containing x and y (virtual units).
setPositionPx
This method will set the Sprite position in pixel coordinates.
void setPositionPx(number x, number y)
Parameters:
numberx: X position (pixels).numbery: Y position (pixels).
getPositionPx
This method will return the Sprite position in pixel coordinates.
{x, y} getPositionPx()
Returns {x, y}:
Table containing x and y (pixels).
setSize
This method will set the Sprite size in virtual screen units.
void setSize(number width, number height)
Parameters:
numberwidth: Width (virtual units).numberheight: Height (virtual units).
getSize
This method will return the Sprite size in virtual screen units.
{width, height} getSize()
Returns {width, height}:
Table containing width and height (virtual units).
setSizePx
This method will set the Sprite size in pixel coordinates.
void setSizePx(number width, number height)
Parameters:
numberwidth: Width (pixels).numberheight: Height (pixels).
getSizePx
This method will return the Sprite size in pixel coordinates.
{width, height} getSizePx()
Returns {width, height}:
Table containing width and height (pixels).
setColor
This method will set the Sprite color.
void setColor(number r, number g, number b)
Parameters:
numberr: The red color component in RGB model.numberg: The green color component in RGB model.numberb: The blue color component in RGB model.
getColor
This method will return the Sprite color.
{r, g, b, a} getColor()
Returns {r, g, b, a}:
Table containing color in RGBA model.
setAlpha
This method will set the Sprite alpha.
void setAlpha(number alpha)
Parameters:
numberalpha: Opacity value (0-255).
getAlpha
This method will return the current Sprite alpha (opacity).
number getAlpha()
Returns number:
Opacity value (0-255).
setFile
This method will set the Texture file name.
void setFile(string file)
Parameters:
stringfile: Texture file name.
getFile
This method will return the Texture file name.
string getFile()
Returns string:
Texture file name.
setVisible
This method will set whether the Sprite should be rendered.
void setVisible(boolean visible)
Parameters:
booleanvisible: True to render, false to hide.
getVisible
This method will return whether the Sprite is visible.
boolean getVisible()
Returns boolean:
True if visible.
bringToFront
This method will move the Sprite to the front of the render order.
void bringToFront()
getUVRect
Returns the normalized texture rectangle; screen position and size are independent.
table getUVRect()
Returns table:
{x, y, width, height} in normalized UV coordinates.
setUVRect
Sets the normalized texture rectangle. Coordinates must be finite; values outside 0..1 follow renderer addressing behavior.
void setUVRect(number u, number v, number width, number height)
Parameters:
numberu: Left texture coordinate.numberv: Top texture coordinate.numberwidth: Texture rectangle width.numberheight: Texture rectangle height.
Callbacks
No callbacks.