Skip to content
Download

Play sounds

You want to play a sound effect when something happens.

  1. Drag the .wav file into the Recursos (Resources) panel. The name of the sound is the name of the file without the .wav.
  2. In the code, play it by name:
Audio::play("explosao");
  • Audio::play(name) starts playing the sound and returns right away: the game doesn’t stop to wait.
  • Several sounds can play at the same time.
  • For now, Brasa plays WAV files.

Volume (from 0 to 1):

Audio::play("tiro", {.volume = 0.4f});

Looping music, stopping it later:

// in the class: SoundId music_ = 0;
music_ = Audio::play("musica", {.volume = 0.6f, .loop = true});
// ... later:
Audio::stop(music_);

Audio::stopAll() stops all the sounds.