Documentation Index
Fetch the complete documentation index at: https://mintlify.com/OmarMtya/enginejs-module/llms.txt
Use this file to discover all available pages before exploring further.
Figura is the core game-object class in Engine.js. Every visible entity on the canvas — a rectangle, a circle, or an image — is a Figura. It combines a visual description (Transform) with an optional physics component (Rigido) and exposes three methods that the animation loop calls each frame to apply gravity, detect floor contact, and resolve collisions with other rigid figures.
Constructor
new Figura({ id, nombre, tipo, transform, rigido })
Explicit identifier for this figure. The constructor uses a truthy check
(
if(id)), so any falsy value — including 0 or an empty string — is treated
the same as omitting the field and causes an ID to be auto-generated by
Environment.GenerarId(), which returns a random 9-character base-36 string
prefixed with _.Human-readable display name. When omitted, defaults to
"Figura N" where N
is Environment.figuras.length + 1 at the moment of construction.Shape type that controls how the figure is drawn each frame. No validation is
performed in the constructor; only the following values are recognized by the
renderer:
'circulo'— drawn as a filled arc usingtransform.radio'cuadrado'— drawn as a filled rectangle usingtransform.anchura×transform.altura'imagen'— rendered fromtransform.imagen; usesDibujarSpritewhen aSpriteis attached, otherwisedrawImage
Position, size, color, image, and sound data for this figure. See
Transform.
Physics component. When
null (the default) the figure is purely visual and
is excluded from all gravity and collision calculations. See
Rigido.Instance Properties
Unique identifier. Either the value passed to the constructor or the
auto-generated one from
Environment.GenerarId().Display name of the figure.
Shape type string as supplied at construction time.
The Transform instance controlling position, size, color, image, and sound.
See Transform.
The Rigido physics component, or
null if physics are disabled for this
figure. See Rigido.The last figure that landed on top of this one during a rigid-body collision.
Set internally by
tocandoRigidos() on the other figure when it resolves
a downward collision with this one. undefined until a collision occurs.Instance Methods
afectarGravedad()
Advances the figure downward by one gravity step and accelerates the fall for the next frame.
- Adds
rigido.valortotransform.y(moves the figure down by the current speed). - Increases
rigido.valorbyrigido.valor / (Environment.FPS * 100), producing a smooth exponential acceleration.
afectarGravedad() should only be called when rigido is set and
rigido.colision is false. The animation loop is responsible for this
guard; calling it while the figure is already resting will push it through the
floor or through another figure.tocandoFondo()
Returns: boolean
Checks whether the figure has reached the bottom of the canvas and updates the rigido.colision flag accordingly.
- For sprite figures (
transform.imagen.spriteis set), the floor boundary isEnvironment.altura - transform.imagen.sprite.altura. - For all other figures, the boundary is
Environment.altura - transform.altura. - When
transform.y >= fondo: clampstransform.ytofondo, setsrigido.colision = true, and returnstrue. - Otherwise: sets
rigido.colision = falseand returnsfalse.
tocandoRigidos()
Returns: void
Iterates every other figure in Environment.figuras that has a Rigido component with sinColision = false, and resolves any overlap using axis-aligned bounding-box (AABB) detection via Tocando().
Collision resolution steps (when overlap is detected and the other figure is below):
- Repositions this figure so its bottom edge sits flush against the top of the figure below.
- If the figure below is a circle:
newY = figura.transform.y - figura.transform.radio - this.transform.altura - Otherwise:
newY = figura.transform.y - this.transform.altura
- If the figure below is a circle:
- Sets
this.rigido.colision = true. - On the first contact tick (when
figura.tocadoPor != this):- Sets
figura.tocadoPor = this. - Transfers
this.rigido.valortofigura.rigido.valor(the impacted figure inherits the incoming gravity speed). - Resets
this.rigido.valortoEnvironment.gravedad. - Sets
this.rigido.gravedadReiniciada = trueso the next tick does not prematurely setcolision = false.
- Sets
transform.sonido is set with activacion of 'colision' or 'colisionInversa'):
activacion | rigido.colision | Audio state | Action |
|---|---|---|---|
'colision' | true | paused | .play() |
'colision' | false | playing | .pause() |
'colisionInversa' | false | paused | .play() |
'colisionInversa' | true | playing | .pause() |