Vital.sandbox
Engine

engine.draw_line

Client

Draws a polyline through a series of 2D points on the canvas


Syntax

local status = engine.draw_line(
    points, 
    stroke = 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 polyline 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
vector2[]pointsArray of 2D points defining the line path
floatstrokeLine thickness in pixels — set to 0 to disable
colorcolorColor of the line

Returns

TypeNameDescription
boolstatustrue on successful execution, or false on failure

Examples

Draw lines with various styles
network:fetch("vital.sandbox:draw", true):on(function()
    --Draw a simple horizontal line
    engine.draw_line({{0, 100}, {400, 100}}, 2)

    --Draw a colored diagonal line
    engine.draw_line({{0, 0}, {200, 200}}, 4, {1, 0, 0, 1})

    --Draw a multi-segment polyline
    engine.draw_line({{0, 0}, {100, 100}, {200, 0}, {300, 100}}, 2, {0, 1, 0, 1})
end)

On this page