Engine
engine.draw_image
Client
Draws an image on the canvas from a file path or a texture resource
Syntax
local status = engine.draw_image(
position,
size,
texture,
rotation = 0,
pivot = {0, 0},
color = {1, 1, 1, 1}
)Must be called within the vital.sandbox:draw 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
network:fetch("vital.sandbox:draw", true):on(...)and place all canvas 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 | texture | Image source: • string — file path to an image asset• texture — pre-loaded texture instance• rendertarget — rendertarget instance• svg — svg instance |
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, or false on failure |
Examples
local my_texture = texture.create("assets/logo.png")
local my_svg = svg.create("assets/icon.svg")
local my_rt = rendertarget.create(1920, 1080)
network:fetch("vital.sandbox:draw", true):on(function()
--Draw an image from a file path
engine.draw_image({0, 0}, {256, 256}, "assets/logo.png")
--Draw a tinted image
engine.draw_image({100, 100}, {128, 128}, "assets/icon.png", 0, {0, 0}, {1, 0.5, 0.5, 1})
--Draw a rotated image around its center
engine.draw_image({100, 100}, {128, 128}, "assets/arrow.png", math.pi/2, {64, 64})
--Draw from a texture instance
engine.draw_image({0, 0}, {512, 512}, my_texture)
--Draw from an svg instance
engine.draw_image({0, 0}, {256, 256}, my_svg)
--Draw from a rendertarget instance
engine.draw_image({0, 0}, {1920, 1080}, my_rt)
end)