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.
Sonido attaches an HTMLAudioElement to a Transform and declares the condition under which it should play. Engine.js evaluates the activacion mode at two distinct points: at construction time for 'inicial', and inside Figura.tocandoRigidos() every frame for 'colision' and 'colisionInversa'. This makes it straightforward to add ambient loops, landing sounds, or airborne sounds to any Figura that has a Rigido component.
Constructor
new Sonido({ src, activacion })
The audio element to control. Construct it with
new Audio('./path/to/file.mp3')
and pass the element — not a plain string path. The engine calls .play() and
.pause() on this reference directly.Determines when the sound plays. Must be one of
'inicial',
'colision', or 'colisionInversa'. See the table below for details.activacion Modes
| Value | Trigger | Behavior |
|---|---|---|
'inicial' | Scene start | src.play() is called immediately inside the Sonido constructor. The sound should be treated as a looping ambient track; pause it manually or via DetenerAnimacion(). |
'colision' | Collision start/end | Plays when rigido.colision becomes true (figure lands); pauses when rigido.colision becomes false (figure leaves surface). |
'colisionInversa' | No collision | Plays when rigido.colision is false (figure is airborne); pauses when rigido.colision is true (figure is resting). |
Instance Properties
The audio element passed at construction time.
The activation mode string:
'inicial', 'colision', or 'colisionInversa'.Usage
Sound triggering for
'colision' and 'colisionInversa' only occurs inside
Figura.tocandoRigidos(). The figure must have a Rigido component for
these modes to fire — a figure without rigido never calls tocandoRigidos(),
so the sound will never play or pause automatically.