EveryDocumentation 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.
Figura in Engine.js carries a Transform — the single object that describes where on the canvas the figure lives, how large it is, what colour it is filled with, and which image and sound assets are attached to it. You create a Transform when constructing a figure, and you modify it at runtime to move, resize, or restyle objects.
Constructor
x, y, anchura, altura, and relleno. For circles, use x, y, radio, and relleno.
Constructor parameters
Horizontal position of the figure in canvas pixels, measured from the left edge of the canvas.
Vertical position of the figure in canvas pixels, measured from the top edge of the canvas.
Width in pixels. Used by
"cuadrado" (square) and "imagen" (image) figures. Ignored by circles.Height in pixels. Used by
"cuadrado" and "imagen" figures. Ignored by circles.Radius in pixels. Used exclusively by
"circulo" (circle) figures. Has no effect on squares or images.Fill colour as a CSS hex string (e.g.
"#ff0000" for red). This controls the solid fill of squares and circles, and acts as the background colour placeholder for image figures.Runtime properties
In addition to the constructor arguments, theTransform instance also holds two optional asset references that are set after construction:
An
$g.Imagen instance wrapping an HTMLImageElement. When set, the engine draws the image instead of (or in addition to) the fill colour. See the Sprites page for sprite sheet animation.A
$g.Sonido instance defining the sound effect attached to this figure. See the Sounds page for the full activation reference.Code example
Modifying a transform at runtime
Because$g.figuras holds references to the live objects, you can update any transform property directly and then redraw the scene:
$g.Animar() is running, transform changes take effect on the very next frame — there is no need to call $g.Dibujar() manually during animation.
A note on circles
For
"circulo" figures, the engine uses only radio and relleno from the transform. Setting anchura or altura on a circle’s transform has no visual effect and does not influence collision detection. Always use radio when working with circles.Summary table
| Property | Applies to | Description |
|---|---|---|
x | all types | Horizontal canvas position in pixels |
y | all types | Vertical canvas position in pixels |
anchura | square, image | Width in pixels |
altura | square, image | Height in pixels |
radio | circle | Radius in pixels |
relleno | all types | CSS hex fill colour string |
imagen | any | Optional Imagen asset reference |
sonido | any | Optional Sonido asset reference |