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

TypeNameDescription
vector2positionTop-left position to draw the image
vector2sizeWidth and height to render the image at
string | texture | svg | rendertargetmaterialImage source:
string - file path to an image asset
texture - pre-loaded texture instance
rendertarget - rendertarget instance
svg - svg instance
floatrotationRotation angle in degrees
vector2pivotPivot point for rotation, relative to the image's position
colorcolorTint color to multiply over the image

Returns

TypeNameDescription
boolstatustrue on successful execution, false otherwise

Examples

Draw an image from a file path
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)
Draw a tinted image
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)
Draw an image rotated around its center
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)
Draw from a texture instance
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)
Draw from an SVG instance
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)
Draw from a rendertarget instance
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)

On this page