core.engine.draw_image
Client
Draws an image on the canvas from a file path or a texture resource
Syntax
local status = core.engine.draw_image(
position,
size,
material,
rotation = 0,
pivot = {0, 0},
color = {1, 1, 1, 1}
)Must be called within the "sandbox:draw" util.event. Invoking this function outside of that event will have no effect.
- Inside the event — executes as expected, rendering the image to the canvas each frame.
- Outside the event — the call will be silently ignored and nothing will be drawn.
- Recommended usage — register a handler via
util.event.on("sandbox:draw", ...)and place all draw calls inside it.
Parameters
| Type | Name | Description |
|---|---|---|
vector2 | position | Top-left position to draw the image |
vector2 | size | Width and height to render the image at |
string | texture | svg | rendertarget | material | Image source: • string - file path to an image asset• texture - pre-loaded texture instance• rendertarget - rendertarget instance• svg - svg instance |
float | rotation | Rotation angle in degrees |
vector2 | pivot | Pivot point for rotation, relative to the image's position |
color | color | Tint color to multiply over the image |
Returns
| Type | Name | Description |
|---|---|---|
bool | status | true on successful execution, false otherwise |
Examples
local resolution = core.engine.get_resolution()
local center = {resolution[1]*0.5, resolution[2]*0.5}
util.event.on("sandbox:draw", function()
core.engine.draw_image(
{center[1] - 128, center[2] - 128},
{256, 256},
"assets/logo.png"
)
end)local resolution = core.engine.get_resolution()
local center = {resolution[1]*0.5, resolution[2]*0.5}
util.event.on("sandbox:draw", function()
core.engine.draw_image(
{center[1] - 128, center[2] - 128},
{256, 256},
"assets/icon.png",
0,
{0, 0},
{1, 0.5, 0.5, 1}
)
end)local resolution = core.engine.get_resolution()
local center = {resolution[1]*0.5, resolution[2]*0.5}
util.event.on("sandbox:draw", function()
core.engine.draw_image(
{center[1] - 64, center[2] - 64},
{128, 128},
"assets/arrow.png",
90,
{64, 64}
)
end)local resolution = core.engine.get_resolution()
local center = {resolution[1]*0.5, resolution[2]*0.5}
local texture = core.texture.create("assets/logo.png")
util.event.on("sandbox:draw", function()
core.engine.draw_image(
{center[1] - 128, center[2] - 128},
{256, 256},
texture
)
end)local resolution = core.engine.get_resolution()
local center = {resolution[1]*0.5, resolution[2]*0.5}
local svg = core.svg.create("assets/icon.svg")
util.event.on("sandbox:draw", function()
core.engine.draw_image(
{center[1] - 128, center[2] - 128},
{256, 256},
svg
)
end)local resolution = core.engine.get_resolution()
local center = {resolution[1]*0.5, resolution[2]*0.5}
local rendertarget = core.rendertarget.create(1920, 1080)
util.event.on("sandbox:draw", function()
core.engine.draw_image(
{center[1] - 200, center[2] - 113},
{400, 225},
rendertarget
)
end)