Reader small image

You're reading from  Torque 3D Game Development Cookbook

Product typeBook
Published inJan 2013
Reading LevelIntermediate
PublisherPackt
ISBN-139781849693547
Edition1st Edition
Languages
Right arrow
Author (1)
DAVID WYAND
DAVID WYAND
author image
DAVID WYAND

David Wyand has been using GarageGames' Torque Game Engine for the past 10 years. Among his other interestes are 3D graphics applications, computer networking and Artificial Intelligence for computer games.
Read more about DAVID WYAND

Right arrow

Chapter 6. Make That Sound Happen

In this chapter, we will cover the following topics:

  • Playing a quick 2D or 3D sound on all clients

  • Using SFXEmitter to create networked sound effects

  • Playing a sound on a ShapeBase object

  • Playing music while a level is loading

  • How to have a background sound for a level

  • How to have music change according to the mood

  • Triggering an event during sound playback

Introduction


To paraphrase a famous writer and director:

Sound is 50 percent of the experience.

Torque 3D's sound system helps us build that second 50 percent into our games by providing us with a variety of options.

It starts by allowing for a number of different sound providers to choose from (OpenAL, DirectSound, XAudio, and FMOD) and wraps all that in a standard SFX layer, while still keeping robust access. In this chapter, we will touch the surface of what is available in Torque 3D's sound system.

Playing a quick 2D or 3D sound on all clients


Torque 3D allows the game developer to broadcast either a 2D or 3D sound event to all clients connected to a server during gameplay. This is true even during a single-player game as Torque 3D internally still has a client/server environment.

In this recipe, we will learn the TorqueScript commands to issue sound events and discover their limitations.

Getting ready

We will be using a project based on the Torque 3D's Full template and issuing console commands using the Empty Terrain level. If you haven't already, use the Torque Project Manager (Project Manager.exe) to create a new project from the Full template. It will be found under the My Projects directory. Then start up our new Full template game and load the Empty Terrain level.

How to do it...

In the following steps we will trigger 2D and 3D sounds that play on all clients:

  1. Open the console using the tilde (~) key and enter the following at the bottom of the screen to play a 2D sound on all...

Using SFXEmitter to create networked sound effects


While Torque 3D makes it easy to play single, short sound effects at any time (see the previous recipe), there are times when we need to play longer sound effects that all clients need to hear when they connect to the game server, or when they are in range (for 3D effects).

In this recipe, we will learn how to set up a sound source that will be in scope for all clients, new or old, and will automatically handle clients that come in range.

Getting ready

We will be making TorqueScript changes and working with World Editor in a project based on the Torque 3D's FPS Tutorial template. We will then try them out using the China Town Day level.

If you haven't already, use the Torque Project Manager (Project Manager.exe) to create a new project from the FPS Tutorial template; it can be found under the My Projects directory. Then start your favorite script editor, such as Torsion, and let's get going!

How to do it...

In the following steps, we will play...

Playing a sound on a ShapeBase object


All ShapeBase class objects are able to play up to four simultaneous sounds that track position of the object. In this recipe, we will learn how to play and stop sounds on a ShapeBase object.

Getting ready

We will be issuing console commands in a project based on the Torque 3D's FPS Tutorial template, and try them out using the China Town Day level. If you haven't already, use the Torque Project Manager (Project Manager.exe) to create a new project from the FPS Tutorial template; it can be found under the My Projects directory.

Subsequently, start the game and load the China Town Day level. You may want to change settings of the level just prior to playing to make sure we don't change levels while experimenting. Set the Time Limit to Infinite and uncheck the Map Cycle setting.

How to do it...

In the following steps, we will make a ShapeBase object in the level play different sound effects:

  1. After the China Town Day level starts, run the player over to the...

Playing music while a level is loading


Waiting for a level to load on a multiplayer client can take some time, especially for large levels with a lot of content. Having music play during this downtime can help pass the time. In this recipe, we will learn how to play music while a level is loading, and how to stop the music once the level has loaded.

Getting ready

We will be making TorqueScript changes and working with the World Editor in a project based on the Torque 3D's FPS Tutorial template, and try them out using the China Town Day level. If you haven't already, use the Torque Project Manager (Project Manager.exe) to create a new project from the FPS Tutorial template; it can be found under the My Projects directory.

How to do it...

In the following steps we will set up some music to play while the level is loading:

  1. Start the FPS Tutorial game and load the China Town Day level.

  2. Press F11 to open World Editor; make sure the Object Editor is active (F1 or by using the Editors menu).

  3. Go to the...

How to have a background sound for a level


Sometimes, you want a background sound loop that just plays continuously while playing a level. It could be howling wind, heavy rain, and so on. Torque 3D makes it easy to add a 2D sound to any level, and have it start playing as soon as the level loads. In this recipe, we will learn how to add a continuously playing 2D sound to a level.

Getting ready

We will be working with the World Editor in a project based on the Torque 3D's FPS Tutorial template. If you haven't already, use the Torque Project Manager (Project Manager.exe) to create a new project from the FPS Tutorial template; it can be found under the My Projects directory.

How to do it...

In the following steps we will have a looping sound play continuously while playing a level:

  1. Start up our FPS Tutorial game and load the China Town Mist level.

  2. Press F11 to open the World Editor. As we want to work with objects in the scene, the Object Editor should be selected (F1 or by using the Editors menu...

How to have music change according to the mood


Torque 3D allows us to change the sounds that are playing based on various states. One example is modifying the background music of a level depending on the current mood, or to reflect a change that has occurred in the game.

In this recipe, we will learn how change the music currently being played, depending on if the player is being hurt through the use of mood states.

Getting ready

We will be making TorqueScript changes and working with the World Editor in a project based on the Torque 3D's FPS Tutorial template, and try them out using the China Town Dusk level.

If you haven't already, use the Torque Project Manager (Project Manager.exe) to create a new project from the FPS Tutorial template; it can be found under the My Projects directory. After that, start your favorite script editor, such as Torsion, and let's get going!

How to do it…

In the following steps, we will set up some audio mood ambiences that will be switched between, when the player...

Triggering an event during sound playback


Torque 3D allows us to set markers on the timeline of a sound that triggers a callback. In this recipe, we will learn how to set markers on a sound source and respond to their callback while a sound is playing.

Getting ready

We will be making TorqueScript changes in a project based on the Torque 3D's FPS Tutorial template, and try them out using the China Town Day level. If you haven't already, use the Torque Project Manager (Project Manager.exe) to create a new project from the FPS Tutorial template; it can be found under the My Projects directory. After that, start your favorite script editor, such as Torsion, and let's get going!

How to do it...

In the following steps we will have an explosion trigger based on a sound playing:

  1. Open scripts/client/game.cs in a text editor, add the following TorqueScript code to the bottom of the file, and save it:

    // This function will create an explosion one of the
    // street lamps as indicated by %lampIndex.
    function...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Torque 3D Game Development Cookbook
Published in: Jan 2013Publisher: PacktISBN-13: 9781849693547
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
DAVID WYAND

David Wyand has been using GarageGames' Torque Game Engine for the past 10 years. Among his other interestes are 3D graphics applications, computer networking and Artificial Intelligence for computer games.
Read more about DAVID WYAND