Skip to content
Download

Drawing

Each instance draws its own sprite. To draw something else, use these functions inside onRender (in the world, with camera) or onRenderGui (on screen, on top of everything).

Function What it does
drawSelf() Draws the instance sprite, with its scale, angle and position.
drawSprite(sprite, frame, x, y) Draws a sprite at a position. Optional: X scale, Y scale, angle and alpha (0 to 1).
drawRect(x, y, width, height, color) Draws a rectangle. A last argument false draws only the outline.
drawLine(x1, y1, x2, y2, color) Draws a line.
drawText(text, x, y, color) Writes with the built-in font (8-pixel letters). A fifth argument scales it: 2 = 16 pixels.
drawText(text, x, y, color, font, size) Writes with a project font (.ttf), at the given size in pixels.
function onRender(self)
self:drawSelf()
drawRect(self.x - 8, self.y - 14, 16 * self.vida, 2, colors.red)
end
function onRenderGui(self)
drawText("Pontos: " .. self.pontos, 4, 4, colors.white)
end

A color has r, g, b and a (opacity), from 0 to 255. Ready-made: white, black, red, green, yellow and magenta.

local laranja = Color(255, 90, 31)
local sombra = Color(0, 0, 0, 128)
drawRect(0, 0, 320, 180, sombra)
  • The layer decides the order: the top of the list is in front. Each layer has a depth, and higher is further back.
  • setLayer(layer) moves the instance to another layer; changing depth also works.
  • onRenderGui is drawn on top of all onRender.
  • For HUD and menus, use the Interface.