GTCS Game Engine:
Expanded Audio Functionality Tutorial

Back to V3 Documentation Page


Introduction

In this tutorial, we will look at extra support added to the audio part of the engine.

Important notes:

-recommend that when working with volume, don't use any form of headphones/headset

-recommend not using with a value over 100 when starting to figure out what volume is desired for the game

-to use audio functions start with gEngine.AudioClips.(insert function name here)

-in audio terms "gain" means "volume"

Audio Info: Master VolumeBackground AudioCue


Master Volume

All audio goes through a master gain (volume) node. Any adjustements made to the master volume will affect all audio in the game. (e.g. master volume set to 0 mutes the game)

Functions:

setMasterVolume - sets the master volume to a given value

incMasterVolume - increments the master volume by a given value (positive or negative)

MyGame.prototype.initialize = function() {
    gEngine.AudioClips.setMasterVolume(10);
};

Example of setting master volume

MyGame.prototype.update = function() {
	if(gEngine.Input.isKeyClicked(gEngine.Input.keys.Right)){
            gEngine.AudioClips.incMasterVolume(10);
        }
	if(gEngine.Input.isKeyClicked(gEngine.Input.keys.Left)){
            gEngine.AudioClips.incMasterVolume(-10);
        }
};

Example of incrementing master volume


Background Audio

This section looks at how to use background audio in a game (such as background music). Any volume adjustments here only affect the background audio.

Note: there can only be one background audio playing at a time

Functions:

playBackgroundAudio - this function takes in a string indicating the location of the background audio file and then starts playing it

stopBackgroundAudio - this function stops the background audio

isBackgroundAudioPlaying - returns whether or not there is currently background audio being played

setBackgroundVolume - sets the background audio volume to a given value

incBackgroundVolume - increments the background audio volume by a given value (positive or negative)


Cue

This section looks at how to play an audio cue. An audio cue is a sound played only once (like a sound to accompany an item pick-up). Each cue is played with its own volume. However, there is an overall cue volume too which allows for manipulation of all cues' volumes at once.

Functions:

playACue - this function takes in a string indicating the location of the cue audio file and a volume value

setCueVolume - sets the overall cue volume to a given value


Conclusion

With these expanded audio funtionalities, we can make adjustments (and allow for user adjuments) to the in-game volumes. This means the user does not have to adjust the volume of the computer they are using to play the game. Also, the different volumes (master, background, and cue) can be adjusted individually allowing us to balance out different audios.

Back to V3 Documentation Page

6/1/2019 - Kyla NeSmith