Skip to content
dgough edited this page Dec 21, 2012 · 4 revisions

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.

Creating an AudioSource

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");

Playing the AudioSource

The following example illustrates how to play audio:

wheelsSound->play();

Updating the AudioListener

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().

Audio Properties

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
}

Binding an AudioSource to a node

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.

Clone this wiki locally