TheDocumentation 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 class lets you tie an HTMLAudioElement to a figure’s lifecycle. Rather than calling play() and pause() yourself, you declare when the sound should be active using the activacion property, and Engine.js handles the rest inside its physics loop and initialization routine.
The Sonido Class
| Parameter | Type | Required | Description |
|---|---|---|---|
src | HTMLAudioElement | ✅ | A native browser Audio object pointing to your sound file |
activacion | string | ✅ | One of 'inicial', 'colision', or 'colisionInversa' — controls when playback is triggered |
Activation Modes
- inicial
- colision
- colisionInversa
The sound plays immediately when
Sonido is constructed, and again every time Inicializar() runs at the start of an animation loop. When DetenerAnimacion() is called, Engine.js automatically calls .pause() on every 'inicial' sound.Use this for: background music, ambient loops, intro sounds.Activation Mode Summary
activacion | Plays when… | Pauses when… | Managed by… |
|---|---|---|---|
'inicial' | Sonido is constructed & on Inicializar() | DetenerAnimacion() | Constructor + motor.js |
'colision' | rigido.colision === true | rigido.colision === false | tocandoRigidos() |
'colisionInversa' | rigido.colision === false | rigido.colision === true | tocandoRigidos() |
Attaching Sound to a Figure
Pass aSonido instance to the sonido property of a Transform. Sound is part of the transform, not the figure directly.
Full Example
The example below shows a player figure that plays a wind effect while airborne and a landing thud when it touches the floor:How Engine.js Manages Playback
For'colision' and 'colisionInversa' modes, Engine.js checks the figure’s audio state on every physics tick inside tocandoRigidos():
'colisionInversa' the logic is inverted — play() is called when colision is false and pause() when it is true.
For 'inicial' sounds, Inicializar() calls .play() at the start of every animation loop, and DetenerAnimacion() calls .pause() on the same sounds when the loop is cancelled:
'colision' and 'colisionInversa' are only evaluated inside tocandoRigidos(), which runs as part of Engine.js’s physics step. This means the figure must have a Rigido component for either of these modes to work. Additionally, the Rigido component must not have sinColision set to true — figures marked with sinColision skip collision detection entirely and their sound state will never be updated. A figure without rigido, or with rigido.sinColision = true, will never have its sound triggered or paused by collision state.Next Steps
Physics & Collisions
How
Rigido and collision detection workCollision Detection Guide
Detecting and responding to collisions
Animation Loop
IniciarAnimacion and DetenerAnimacion in depthSonido API
Full
Sonido API reference