-
Notifications
You must be signed in to change notification settings - Fork 6
Working with sound
To play a sound over all platforms, you need to save/encode your sound to different extensions (like this: mySound.m4a, mySound.mp3, mySound.ogg). Again, you don't need to add the extension, Flambe will use the right sound for the right platform. More on loading (external) assets, read Working with assets.
pack.getSound("mySound").play();
The play()
and loop()
of a Sound
instance returns a Playback
instance. You can use it to manipulate the volume, get the duration or pause,play and stop the sound.
var mySoundPlayback = pack.getSound("mySound").play();
var myLoopingSoundPlayback = pack.getSound("mySound").loop();
Volume values are from 0-1.
// directly set volume when you start the sound to half volume (0.5)
pack.getSound("mySound").play(0.5);
// .. or set the volume afterwards
mySoundPlayback.volume._ = 0.5; // set volume to half volume
// .. or fade the sound in one second to half volume
mySoundPlayback.volume.animateTo(0.5, 1);
To understand the animate and underscore syntax, read Working with values.
mySoundPlayback.paused = true; // set to pause
mySoundPlayback.dispose(); // stop sound and remove
If you want to alter the global volume which affects all samples, or want to mute all sounds, you should do that into the System
.
System.volume._ = 0; // mute all sounds
System.volume._ = 1; // unmute
System.volume.animateTo(0.5, 1); // fade global volume to half volume (0.5) in 1 second.
- Not all Android devices seems to play sound. On slow/older android devices sound are laggy or don't play instantly which could cause timing issues.
- On iOS5 (like iphone4) sound require user input. This is not build in Flambe, so it won't work. On higher versions sounds seems to work very good.
Documentation guide for Flambe - Targeted to version 4.0+
Flambe | Installation | Demo projects | Showcase | API Reference | Forum
Flambe is MIT licensed and available for free. Feel free to contribute!
- Home / Installation
- Entity / Components
- Core
- Assets
- Publish your game
- Other
- Editors
- Plugins, tools, extensions
- Help
- More Flambe