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.
$g.Sonido gives each game object its own sound effect, independently of the optional global background audio. A Sonido instance wraps a native HTMLAudioElement and an activacion string that tells the engine when to call .play() on that element. The instance is stored on figura.transform.sonido and the engine checks it on every relevant event during the animation loop.
Constructor
The
Audio object that the engine will play. Pass null to reserve the slot before a file has been loaded — the engine will skip playback silently until a real Audio object is assigned. Create one with new Audio() and set its src property to a URL or an object URL from a File.The trigger mode that determines when the sound plays. Accepted values:
'inicial'— plays once when$g.Animar()starts'colision'— plays each time this figure collides with another rigid body'colisionInversa'— plays when this figure stops colliding (separation event)
Activation Modes
| Value | When it fires |
|---|---|
'inicial' | Once, at the moment $g.Animar() begins the loop |
'colision' | Each time the figure enters a collision with another rigid-body figure |
'colisionInversa' | Each time the figure exits (separates from) a collision |
Examples
Attaching a collision sound from a file input
Playing a sound at scene start
Playing a sound on separation
Reserving the slot before a file is chosen
The editor creates theSonido instance when the checkbox is ticked, before the user picks an audio file:
Changing the trigger mode at runtime
Removing the sound
The
src.title property is used by the built-in editor to display the audio file name in the attributes panel. If you are building a custom editor UI or want to label sounds for debugging, set this property after creating the Audio object: