SpriteTask
A task for rendering a single Sprite from newSprite
This page is a WIP. It contains all the information in Figura's documentation but we're working on adding more helpful descriptions.
For this entire page assume:
local mySprite = models:newSprite("myCoolSpriteName")
Sprite Task
setTexture()
Aliases: texture()
Sets this task's texture
The texture's width and height must be provided if the texture is a location
For custom textures, the dimensions are optional
- Overload 1
- Overload 2
- Overload 3
- Overload 4
- Overload 5
setTexture(textureLocation, width, height)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
textureLocation | String | - | - |
width | Integer | - | - |
height | Integer | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setTexture(texture)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texture | Texture | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setTexture(texture, width, height)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texture | Texture | - | - |
width | Integer | - | - |
height | Integer | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setTexture(textureLocation, dimensions)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
textureLocation | String | - | - |
dimensions | Vector2 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setTexture(texture, dimensions)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texture | Texture | - | - |
dimensions | Vector2 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
Example:
-- using a resource location
mySprite:setTexture("textures/item/turtle_egg.png", 16, 16)
-- using a custom texture
mySprite:setTexture(textures["myTexture"])
-- using a custom texture with dimensions
mySprite:setTexture(textures["myTexture"], 16, 16)
getTexture()
Returns this task's current texture
getTexture()
Returns:
Type | Description |
---|---|
String | - |
Example:
mySprite:getTexture()
setColor()
Aliases: color()
Sets a color multiplier for this sprite
Values are RGBA from 0 to 1
Default values are 1, alpha is optional
- Overload 1
- Overload 2
- Overload 3
setColor(rgb)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgb | Vector3 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setColor(rgba)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba | Vector4 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setColor(r, g, b, a)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
r | Number | - | - |
g | Number | - | - |
b | Number | - | - |
a | Number | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
Example:
mySprite:setColor(world.getBiome():getWaterColor())
getColor()
Gets the current color multiplier of this sprite
Values are RGBA from 0 to 1
getColor()
Returns:
Type | Description |
---|---|
Vector4 | - |
Example:
mySprite:getColor()
setDimensions()
Aliases: dimensions()
Sets the texture dimensions, used in UV calculation
- Overload 1
- Overload 2
setDimensions(dimensions)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dimensions | Vector2 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setDimensions(width, height)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width | Integer | - | - |
height | Integer | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
Example:
-- use the long water_flow texture then make it one block
mySprite:setTexture("textures/block/water_flow.png", 16, 16)
mySprite:setDimensions(32, 1024)
getDimensions()
Returns the texture dimensions, used in UV calculation
getDimensions()
Returns:
Type | Description |
---|---|
Vector2 | - |
Example:
mySprite:getDimensions()
setRegion()
Aliases: region()
Sets the texture UV region
Uses its dimensions to calculate the max UV
- Overload 1
- Overload 2
setRegion(region)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
region | Vector2 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setRegion(width, height)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width | Integer | - | - |
height | Integer | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
Example:
mySprite:setRegion(64, 64)
getRegion()
Gets the texture UV region
getRegion()
Returns:
Type | Description |
---|---|
Vector2 | - |
Example:
mySprite:getRegion()
setRenderType()
Aliases: renderType()
Sets the current render type of this sprite
TRANSLUCENT by default
Check the docs enum command for all render types
setRenderType(renderType)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
renderType | String | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
Example:
mySprite:setRenderType("CUTOUT")
getRenderType()
Gets the name of the current render type for this sprite
getRenderType()
Returns:
Type | Description |
---|---|
String | - |
Example:
mySprite:getRenderType()
setSize()
Aliases: size()
Sets the width and height used to render this sprite
- Overload 1
- Overload 2
setSize(size)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size | Vector2 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setSize(width, height)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width | Integer | - | - |
height | Integer | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
Example:
-- make my small egg bigger
mySprite:setTexture("textures/item/turtle_egg.png", 8, 8)
mySprite:setSize(16, 16)
getSize()
Returns the width and height used to render this sprite
getSize()
Returns:
Type | Description |
---|---|
Vector2 | - |
Example:
mySprite:getSize()
setUV()
Aliases: uv()
Sets this texture UV offset
The Region and Dimension are used to calculate the end UV
- Overload 1
- Overload 2
setUV(uv)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uv | Vector2 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setUV(u, v)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u | Number | - | - |
v | Number | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
Example:
-- Let's make a sprite task of flowing water!
mySprite:setTexture("textures/block/water_flow.png", 16, 16)
mySprite:setDimensions(32, 1024)
mySprite:setColor(world.getBiome():getWaterColor())
local t = 0
function events.tick()
mySprite:setUV(1, t / 32)
t = t + 1
end
getUV()
Gets this texture UV offset
getUV()
Returns:
Type | Description |
---|---|
Vector2 | - |
Example:
mySprite:getUV()
setUVPixels()
Aliases: uvPixels()
Set this texture UV offset, in pixels, based on the texture's dimension
- Overload 1
- Overload 2
setUVPixels(uv)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uv | Vector2 | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
setUVPixels(u, v)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u | Number | - | - |
v | Number | - | - |
Returns:
Type | Description |
---|---|
SpriteTask | Returns self for chaining |
Example:
-- Let's make a sprite task of flowing water!
mySprite:setTexture("textures/block/water_flow.png", 16, 16)
mySprite:setDimensions(32, 1024)
mySprite:setColor(world.getBiome():getWaterColor())
local t = 0
function events.tick()
mySprite:setUVPixels(1, t)
t = t - 1
end
getUVPixels()
Get this texture UV offset, in pixels, based on the texture's dimension
getUVPixels()
Returns:
Type | Description |
---|---|
Vector2 | - |
Example:
mySprite:getUVPixels()
getVertices()
Returns a table with all 4 vertices of this sprite
Changing the values through other functions will reset those vertices
getVertices()
Returns:
Type | Description |
---|---|
Table | - |
Example:
mySprite:getVertices()
Render Task
setLight()
Aliases: light()
Sets the light override value of this task
Values are given from 0 to 15, indicating the block light and sky light levels you want to use
Passing nil will reset the lighting override for this task
- Overload 1
- Overload 2
setLight(light)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
light | Vector2 | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
setLight(blockLight, skyLight)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blockLight | Integer | - | - |
skyLight | Integer | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
Example:
local blockLight = world.getLightLevel(player:getPos())
local skyLight = world.getSkyLightLevel(player:getPos())
mySprite:setLight(blockLight, skyLight)
getLight()
Returns the light override value of this task
getLight()
Returns:
Type | Description |
---|---|
Vector2 | - |
Example:
mySprite:getLight()
setMatrix()
Aliases: matrix()
Sets the given matrix as the position matrix for this render task
The normal matrix is automatically calculated as the inverse transpose of this matrix
Calling this DOES NOT CHANGE the values of position, rot, or scale in the render task
If you call setPos() or a similar function, the effects of setMatrix() will be overwritten
setMatrix(matrix)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix | Matrix4 | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
Example:
mySprite:setMatrix(matrices.mat4())
getName()
Get this task's name
getName()
Returns:
Type | Description |
---|---|
String | - |
Example:
mySprite:getName()
getNormalMatrix()
Recalculates the normal matrix for this render task, based on its current position, rotation, scale, and pivot, then returns this matrix
getNormalMatrix()
Returns:
Type | Description |
---|---|
Matrix3 | - |
Example:
mySprite:getNormalMatrix()
getNormalMatrixRaw()
Returns the normal matrix for this render task
The Raw version of the function is different in that it doesn't recalculate the matrix before returning it
getNormalMatrixRaw()
Returns:
Type | Description |
---|---|
Matrix3 | - |
Example:
mySprite:getNormalMatrixRaw()
setOverlay()
Aliases: overlay()
Sets the overlay override value of this task
Values you give are 0 to 15, indicating the white overlay and the damage overlay levels you want to use
Passing nil will reset the overlay override for this task
- Overload 1
- Overload 2
setOverlay(overlay)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
overlay | Vector2 | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
setOverlay(whiteOverlay, hurtOverlay)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
whiteOverlay | Integer | - | - |
hurtOverlay | Integer | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
Example:
local hurt = player:getNbt.HurtTime > 0
mySprite:setOverlay(hurt and 0 or nil, 1)
getOverlay()
Returns the overlay override value of this task
getOverlay()
Returns:
Type | Description |
---|---|
Vector2 | - |
Example:
mySprite:getOverlay()
setPos()
Aliases: pos()
Sets the position of the task, relative to its attached part
Uses model coordinates
- Overload 1
- Overload 2
setPos(x, y, z)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Number | - | - |
y | Number | - | - |
z | Number | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
Example:
mySprite:setPos(0, 16, 0)
getPos()
Gets this task position
getPos()
Returns:
Type | Description |
---|---|
Vector3 | - |
Example:
mySprite:getPos()
getPositionMatrix()
Recalculates the matrix for this render task, based on its current position, rotation, scale, and pivot, then returns this matrix
getPositionMatrix()
Returns:
Type | Description |
---|---|
Matrix4 | - |
Example:
mySprite:getPositionMatrix()
getPositionMatrixRaw()
Returns the position matrix for this render task
The Raw version of the function is different in that it doesn't recalculate the matrix before getting it
getPositionMatrixRaw()
Returns:
Type | Description |
---|---|
Matrix4 | - |
Example:
mySprite:getPositionMatrixRaw()
setRot()
Aliases: rot()
Sets the rotation of the task, relative to its attached part
- Overload 1
- Overload 2
setRot(x, y, z)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Number | - | - |
y | Number | - | - |
z | Number | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
Example:
mySprite:setRot(0, 45, 22.5)
getRot()
Gets this task rotation
getRot()
Returns:
Type | Description |
---|---|
Vector3 | - |
Example:
mySprite:getRot()
setScale()
Aliases: scale()
Sets the scale of the task, relative to its attached part
- Overload 1
- Overload 2
setScale(scale)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale | Vector3 | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
setScale(x, y, z)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Number | - | - |
y | Number | - | - |
z | Number | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
Example:
mySprite:setScale(0.4, 0.4, 0.4) -- mySprite:setScale(0.4) also works
getScale()
Gets this task scale
getScale()
Returns:
Type | Description |
---|---|
Vector3 | - |
Example:
mySprite:getScale()
setVisible()
Aliases: visible()
Sets whether or not this task should be rendered
setVisible(visible)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
visible | Boolean | - | - |
Returns:
Type | Description |
---|---|
RenderTask | - |
Example:
local myPage = action_wheel.newPage()
myPage:newAction():setOnToggle(function(state)
mySprite:setVisible(state)
end)
isVisible()
Checks if this task is visible
isVisible()
Returns:
Type | Description |
---|---|
Boolean | - |
Example:
if mySprite:isVisible() then
-- do something
end
remove()
Removes this render task from the parent model part
remove()
Returns:
Type | Description |
---|---|
RenderTask | - |
Example:
mySprite:remove()