draw

Let's you draw things to the screen.

IMPORTANT

A single call to any methods of draw will not keep drawing, it is just for one single frame.

Therefore in order to render something every frame, attach an eventlistener to the engine

and listen to the render event, like in the examples below.

Methods

draw.text(content, pos, color, fontSize, fontName)

  • content - The text you wish to draw

  • pos - The screen position where to draw the text as a Vec2

  • color - The color of the text as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red with 100% alpha

  • fontSize - The size of the text in pixels

  • fontName - The name of the font

Available Font sizes:

  • 12, 14, 16, 18, 24, 32, 36, 48, 60

Available Fonts:

  • Verdana

  • VerdanaBold

  • Impact

  • Beyblade

  • Dameron

  • RobotoMono-Light

Draws text at a position.

Example:

function render()
	draw.text("Hey", Vec2:new(200, 200), Vec4:new(255, 0, 0, 255), 60, "Verdana")
end

engine.addEventListener("render", render)
Drawing text

draw.line(start, end, color, thickness)

  • start - Start position of the line as a Vec2

  • end - End Position of the line as a Vec2

  • color - The color of the line as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red with 100% alpha

  • thickness - The thickness of the line in pixels

Draws a line from point A to B.

Example:

function render()
	draw.line(Vec2:new(200,300), Vec2:new(500, 500), Vec4:new(255, 0, 0, 255), 2, "Verdana")
end

engine.addEventListener("render", render)
Drawing a line

draw.rectangle(topLeft, botRight, color, rounding)

  • topLeft - Top left corner as a Vec2

  • botRight- Bottom right corner as a Vec2

  • color - The color of the rect as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red with 100% alpha

  • rounding- Edge rounding in pixels

Draws a rectangle spanning from topLeft to botRight.

Example:

function render()
	draw.rectangle(Vec2:new(200,200), Vec2:new(250, 300), Vec4:new(255, 0, 0, 255), 0)
end

engine.addEventListener("render", render)
Drawing a rectangle

draw.rectangleFilled(start, end, color, thickness)

  • topLeft - Top left corner as a Vec2

  • botRight- Bottom right corner as a Vec2

  • color - The color of the rect as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red with 100% alpha

  • rounding- Edge rounding in pixels

Draws a filled rectangle spanning from topLeft to botRight.

Example:

function render()
	draw.rectangleFilled(Vec2:new(200,200), Vec2:new(250, 300), Vec4:new(255, 0, 0, 255), 0)
end

engine.addEventListener("render", render)
Drawing a filled rectangle

draw.circle(center, radius, color, segments)

  • center - The center of the circle as a Vec2

  • radius - The radius of the circle in pixels

  • color - The color of the circle as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red

  • segments - The circle is made up of lines, the more segments the smoother

Draws a circle.

Example:

function render()
	draw.circle(Vec2:new(200,300), 60, Vec4:new(255, 0, 0, 255), 20)
end

engine.addEventListener("render", render)
Drawing a circle

draw.circleFilled(center, radius, color, segments)

  • center - The center of the circle as a Vec2

  • radius - The radius of the circle in pixels

  • color - The color of the circle as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red

  • segments - The circle is made up of lines, the more segments the smoother

Draws a filled circle.

Example:

function render()
	draw.circleFilled(Vec2:new(200,300), 60, Vec4:new(255, 0, 0, 255), 20)
end

engine.addEventListener("render", render)

Last updated