Renderer

local Renderer = require('encompass').Renderer

A Renderer is an Engine which is responsible for reading components to draw elements to the screen.

Renderers are defined by the Component prototype(s) they track, of which exactly one must be a DrawComponent, and the render function they implement.

It is an anti-pattern to modify Entities or Components from inside a Renderer. Do not do this.

Function Reference

Renderer.define(name, component_types)
Arguments:
  • name (string) – The name of the Renderer
  • component_types (table) – An array-style table containing Components, exactly one of which must be a DrawComponent. If this is not the case, an error will be thrown.

Defines a Renderer that will track Entities which contain all of the given component types.

Renderer:initialize(...)
Arguments:
  • ... (args) – An arbitrary list of arguments.

This callback is triggered when the Renderer is added to the World.

Useful for dealing with side effects, like initializing framebuffers.

Renderer:render(entity, canvas)
Arguments:
  • entity (Entity) – A reference to an entity which is tracked by the Renderer
  • canvas (Canvas) – A reference to the current canvas (framebuffer)

Every frame, this callback runs for each entity tracked by the Renderer. The programmer must override this callback or an error will be thrown.