O'Reilly logo

3D Game Programming for Teens, Second Edition by Eric Grebler, Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading and Playing Sounds

To get a sound file into your program, you first need to load it. After it is loaded, you can assign it to play at specific times. The following code will load a sound:

; Loading a sound
sound = LoadSound (filename)

Obviously, you would replace filename with the actual name of your sound file. For example, in a video game with a blast, you might write:

blaster = LoadSound ("blaster.wav").

The sound part of the code is just a name we gave our sound; you can call your sounds anything you’d like.

Open the file called demo12-01.bb and save it to a new folder. Make sure that the file called blaster.wav is in the same folder. Follow along as we go through the code.

blaster = LoadSound ("blaster.wav")

The game that we have ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required