Vital.sandbox
Engine

engine.draw_rectangle

Client

Draws a filled rectangle on the canvas


Syntax

local status = engine.draw_rectangle(
    position, 
    size, 
    color = {1, 1, 1, 1}, 
    stroke = 0, 
    stroke_color = {1, 1, 1, 1}, 
    rotation = 0, 
    pivot = {0, 0}
)

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 filled rectangle 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

TypeNameDescription
vector2positionTop-left corner of the rectangle
vector2sizeWidth and height of the rectangle
colorcolorFill color of the rectangle
floatstrokeOutline thickness in pixels — set to 0 to disable
colorstroke_colorColor of the outline
floatrotationRotation angle in radians
vector2pivotPivot point for rotation, relative to the rectangle's position

Returns

TypeNameDescription
boolstatustrue on successful execution, or false on failure

Examples

Draw rectangles with various styles
network:fetch("vital.sandbox:draw", true):on(function()
    --Draw a plain white rectangle
    engine.draw_rectangle({100, 100}, {200, 150})

    --Draw a filled green rectangle with a black outline
    engine.draw_rectangle({100, 100}, {200, 150}, {0, 1, 0, 1}, 2, {0, 0, 0, 1})

    --Draw a rotated rectangle around its center
    engine.draw_rectangle({100, 100}, {200, 150}, {1, 0.5, 0, 1}, 0, {1, 1, 1, 1}, math.pi/6, {100, 75})
end)

On this page