class
Sprite (client-side)
Available since version: 0.3.4
Note
If you want to define your own shape (populate vertices manually), use 1st constructor.
To create a Sprite with default fixed rectangular shape (4 vertices) use 2nd constructor.
This class represents 2d image visible on the screen.
Constructor
Sprite(string txt)
Parameters:
string
txt: the texture file to display.
Constructor
Sprite(int x, int y, int width, int height, string txt)
Parameters:
int
x: the x position in virtuals.int
y: the y position in virtuals.int
width: the width size in virtuals.int
height: the height size in virtuals.string
txt: the texture file to display.
Properties
bool
visible
Represents the visibility state of the texture.
zarray&
vertices (read-only)
Represents the array containing the sprite vertices (4 vertices written in counter clockwise order).
bool
linearFilterEnabled
Represents true
linear filtering is enabled (bilerp or anisotropic, depending on game settings), otherwise false
.
bool
autoUpdateViewport
Represents true
if viewport should be automatically recalculated when ui element dimensions are changing, otherwise false
.
Vec2i&
viewportMin
Represents the top-left corner of the UI element's viewport bounds in pixels.
This value is automatically updated when autoUpdateViewport
is enabled,
and reflects the minimum screen-space coordinates enclosing all vertices.
Vec2i&
viewportMax
Represents the bottom-right corner of the UI element's viewport bounds in pixels.
This value is automatically updated when autoUpdateViewport
is enabled,
and reflects the maximum screen-space coordinates enclosing all vertices.
string
file
Represents the file name of displayed image on texture.
int
alphaFunc
Represents the sprite alpha blending function. Alpha Functions
Color&
color
Represents the sprite color in RGBA model.
float
rotation
Represents the rotation of the sprite in degrees. The rotation is performed clockwise around the sprite pivot point.
Methods
top
This method will move the sprite at the end of the render queue. It will be visible at the top of the screen (other elements will be covered by it).
void top()
pushVertex
Note
This method will only work for non-rectangular shape constructed Sprite
.
This method appends the vertex to vertices
array and updates the UV mapping accordingly.
void pushVertex(int x, int y)
Parameters:
int
x: the x position in virtuals.int
y: the y position in virtuals.
pushVertexPx
Note
This method will only work for non-rectangular shape constructed Sprite
.
This method appends the vertex to vertices
array and updates the UV mapping accordingly.
void pushVertexPx(int x, int y)
Parameters:
int
x: the x position in pixels.int
y: the y position in pixels.
popVertex
This method removes the last vertex from vertices
array.
void popVertex()
getPosition
This method will get the sprite position on screen in virtuals.
Vec2i getPosition()
Returns Vec2i
:
the sprite position on screen.
setPosition
This method will set the sprite position on screen in virtuals.
void setPosition(int x, int y)
Parameters:
int
x: the x position in virtuals.int
y: the y position in virtuals.
getPositionPx
This method will get the sprite position on screen in pixels.
Vec2i getPositionPx()
Returns Vec2i
:
the sprite position on screen.
setPositionPx
This method will set the sprite position on screen in pixels.
void setPositionPx(int x, int y)
Parameters:
int
x: the x position in pixels.int
y: the y position in pixels.
getPivotPoint
This method will get the pivot point of the sprite in virtuals (Offset from the center of it).
Vec2i getPivotPoint()
Returns Vec2i
:
the offset in virtuals. The default pivot point value is {x=0,y=0}
setPivotPoint
This method will set the pivot point of the sprite in virtuals (Offset from the center of it). All rotations will be done relative to this point.
void setPivotPoint(int x, int y)
Parameters:
int
x: the x offset in virtuals.int
y: the y offset in virtuals.
getPivotPointPx
This method will get the pivot point of the sprite in pixels (Offset from the center of it).
Vec2i getPivotPointPx()
Returns Vec2i
:
the offset in pixels. The default pivot point value is {x=0,y=0}
setPivotPointPx
This method will set the pivot point of the sprite in pixels (Offset from the center of it). All rotations will be done relative to this point.
void setPivotPointPx(int x, int y)
Parameters:
int
x: the x offset in pixels.int
y: the y offset in pixels.
getSize
This method will get the sprite size on screen in virtuals.
Vec2i getSize()
Returns Vec2i
:
the sprite size on screen.
setSize
This method will set the sprite size on screen in virtuals.
void setSize(int width, int height)
Parameters:
int
width: the width size in virtuals.int
height: the height size in virtuals.
getSizePx
This method will get the sprite size on screen in pixels.
Vec2i getSizePx()
Returns Vec2i
:
the sprite size on screen.
setSizePx
This method will set the sprite size on screen in pixels.
void setSizePx(int width, int height)
Parameters:
int
width: the width size in pixels.int
height: the height size in pixels.
getUV
Available since version: 0.1.10
This method will get the mapping coordinates (UV) of the sprite.
{x, y, width, height} getUV()
Returns {x, y, width, height}
:
the position and size of image on sprite.
setUV
This method will set the mapping coordinates (UV) of the sprite.
void setUV(float x, float y, float width, float height)
Parameters:
float
x: the u position of image on sprite (Default 0.0).float
y: the v position of image on sprite (Default 0.0).float
width: the u size of image on sprite (Default 1.0).float
height: the v size of image on sprite (Default 1.0).
Callbacks
No callbacks.