The sonido service
Reference for the sonido service. Synthesized sound: presets, tones, noise and note sequences.
DescribesFormato 1, API 1 For those who write code This page is generated from the SDK sources.
On this page
Synthesized sound: presets, tones, noise and note sequences.
The types used in the signatures (Vec3, Texto, the selector) are in the API reference.
Functions and properties of sonido#
sonido.tocar#
sonido.tocar(nombre: SonidoPredefinido, opciones?: { volumen?: number; tono?: number; para?: Jugador }): voidPlays a preset sound.
From docs/EJEMPLOS.md, «sonido»:
mundo.alTocar('#moneda', (_m, j) => sonido.tocar('moneda', { para: j }));sonido.tono#
sonido.tono(def: { frecuencia: number; duracion: number; onda?: 'seno' | 'cuadrada' | 'sierra' | 'triangulo'; hasta?: number; volumen?: number; para?: Jugador }): voidSynthesizes a tone.
From docs/EJEMPLOS.md, «sonido»:
mundo.alTocar('#laser', () => sonido.tono({ frecuencia: 900, hasta: 120, duracion: 0.3, onda: 'sierra' }));sonido.secuencia#
sonido.secuencia(notas: { nota: string | number | null; pulsos?: number }[], opciones?: { pulsosPorMinuto?: number; repetir?: boolean; onda?; volumen?: number; para?: Jugador }): numberPlays a sequence of notes. Returns an id to stop it.
From docs/EJEMPLOS.md, «sonido»:
const musica = sonido.secuencia(
[{ nota: 'do4' }, { nota: 'mi4' }, { nota: 'sol4' }, { nota: null }, { nota: 'la4', pulsos: 2 }],
{ pulsosPorMinuto: 240, repetir: true, onda: 'triangulo', volumen: 0.3 }
);sonido.detener#
sonido.detener(id: number): voidStops a sequence. Takes the id returned by sonido.secuencia.
From docs/EJEMPLOS.md, «sonido»:
mundo.alEntrar('meta', () => sonido.detener(musica));sonido.ruido#
sonido.ruido(def: { duracion: number; volumen?: number; filtro?: number; hasta?: number; ataque?: number; para?: Jugador }): voidNoise (explosion, wind, rain, footsteps). filtro, in Hz, makes it deeper; hasta sweeps the filter.
From docs/EJEMPLOS.md, «mundo: luces, ambiente y zonas creadas por el script»:
// Anochece en 20 segundos y se encienden los faroles (luces con "id" en la escena).
reloj.despues(30, () => {
mundo.ambiente({ cielo: 'noche', luzAmbiente: 0.25, sol: { intensidad: 0.1 }, niebla: { desde: 10, hasta: 60 } }, 20);
for (const luz of mundo.luces()) luz.encendida = true;
sonido.ruido({ duracion: 3, filtro: 600, volumen: 0.4, ataque: 1 });
});sonido.muestra#
sonido.muestra(id: string, opciones?: OpcionesSonido): voidPlays a recorded sound from the game (sonidos/<id>.wav or .mp3). Added in version 1.2.
Behavior notes#
sonido.tono also accepts ataque and caida (seconds of the envelope). sonido.ruido is filtered noise: filtro, in Hz, makes it deeper and hasta sweeps the filter (an explosion: { duracion: 0.6, filtro: 2000, hasta: 100 }).
All sound is synthesized. Presets: moneda, salto, golpe, caida, control, victoria, derrota, clic, alerta, tic, luz, poder. Notes are written 'do4', 'fa#5', 'la3' (solfège names); null is a rest.
Complete examples#
Complete scripts from docs/EJEMPLOS.md. Each one assumes a scene containing what it names, and the text keys (interfaz.t('...')) must exist in textos of juego.json.
sonido#
import { juego, mundo, sonido } from '@greengames/sdk';
juego.alIniciar(() => {
mundo.alTocar('#moneda', (_m, j) => sonido.tocar('moneda', { para: j }));
mundo.alTocar('#laser', () => sonido.tono({ frecuencia: 900, hasta: 120, duracion: 0.3, onda: 'sierra' }));
const musica = sonido.secuencia(
[{ nota: 'do4' }, { nota: 'mi4' }, { nota: 'sol4' }, { nota: null }, { nota: 'la4', pulsos: 2 }],
{ pulsosPorMinuto: 240, repetir: true, onda: 'triangulo', volumen: 0.3 }
);
mundo.alEntrar('meta', () => sonido.detener(musica));
});Next#
- The progreso service
- API reference: the eleven services and the common types.
- Scripts: the rules of a script and how it runs inside the room.