Every interactive element you place in an Engine.js scene is a Figura (figure). Figures are the foundational building block of the engine: they carry a type, a position, visual properties, and optional physics and audio data. Understanding how figures are constructed, stored, and rendered is the first step to building anything in Engine.js.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/OmarMtya/engine.js/llms.txt
Use this file to discover all available pages before exploring further.
The Figura class
A Figura is the fundamental game object in Engine.js, exposed on the global $g namespace as $g.Figura. Every object on the canvas — whether a coloured square, a bouncing circle, or a sprite-animated character — is an instance of Figura.
When you create a figure you pass a configuration object with two required keys:
The shape type. One of
"cuadrado" (square), "circulo" (circle), or "imagen" (image).A
$g.Transform instance that defines the figure’s position, size, and fill colour. See the Transform page for the full property reference.Figura:
| Property | Type | Description |
|---|---|---|
id | number | Auto-assigned unique integer identifier. |
nombre | string | Human-readable name shown in the editor hierarchy. |
tipo | string | The shape type ("cuadrado", "circulo", or "imagen"). |
transform | Transform | Spatial and visual properties. |
rigido | Rigido | null | Optional rigid body for physics. null by default. |
transform property also holds references to an optional Imagen (image asset) and Sonido (sound effect) — both are accessed via figura.transform.imagen and figura.transform.sonido.
The three figure types
"cuadrado" — Square
A square (or rectangle) drawn with a solid fill colour. Defined by x, y, anchura (width), and altura (height).
"circulo" — Circle
A circle drawn with a solid fill colour. Defined by x, y, and radio (radius). The anchura and altura properties are not used for rendering circles.
"imagen" — Image object
An image figure renders a bitmap loaded from a file. It shares the same anchura/altura sizing as squares. The image asset is attached after creation via figura.transform.imagen.
The $g.figuras array
All active scene objects are stored in the $g.figuras array. The engine iterates this array every frame to draw and simulate every object. You can read it at any time to inspect or modify existing figures:
Adding figures: $g.AgregarFigura()
Use $g.AgregarFigura(figura) to register a new Figura in the scene. This pushes it into the $g.figuras array and assigns its id. Always call $g.Dibujar() afterwards to update the canvas.
Removing figures
Splice the figure out of$g.figuras by its index, then call $g.Dibujar() to refresh the canvas:
Object ordering and layering
Figures are rendered in the order they appear in$g.figuras. A figure at a higher index is drawn on top of figures at lower indices. To reorder figures programmatically, use splice():
Click detection with $g.clickListener
Engine.js automatically detects clicks on canvas figures and fires a callback when a figure is hit. Assign your handler to $g.clickListener:
Figura object as its only argument. Click detection is active while the scene is not animating; it is temporarily suspended when $g.Animar() is running.
Rendering: $g.Dibujar()
Call $g.Dibujar() any time you make a change that should be reflected on screen (adding a figure, moving it, changing its colour). During animation ($g.Animar()), the engine calls this automatically every frame — you only need to call it manually when the scene is paused or static.