-
Notifications
You must be signed in to change notification settings - Fork 1
Audio
You can integrate 3-D audio into your game using the audio services supported by gameplay. The framework uses a very traditional way of representing audio. The gameplay::AudioController
manages all of the playing audio sources.
An AudioSource can be created from audio files or from a .audio
property file. Ogg audio files are compressed, so they use less memory than .wav files.
AudioSource* wheelsSound = AudioSource::create("res/longboard.wav");
AudioSource* backgroundMusic = AudioSource::create("res/music.ogg");
The following example illustrates how to play audio:
wheelsSound->play();
By default, the AudioListener
is bound to the active camera of the scene. You can manually bind the camera to the gameplay::AudioListener
using gameplay::AudioListener::setCamera()
.
The gameplay::AudioSource
class has methods for modifying the properties of the AudioSource, such as pitch, gain, and velocity.
Audio sources can be loaded from .audio
property files to make it easier to set these properties.
audio fireball
{
path = res/audio/fireball.wav
looped = false
gain = 0.7
pitch = 0.5
velocity = 0.5 0.0 1.0
}
An AudioSource
can be bound to a Node
in your scene using Node::setAudioSource()
. The position of the audio source is automatically updated when the node is transformed.