Tutorial:AddingSound

From FANG

Jump to: navigation, search

These instructions assume you already know how to make a basic game using the FANG Engine.

These instructions are currently available for two different IDEs (Integrated Development Environment):

The instructions below correspond to the JavaWIDE instructions. If you would like the instructions for any of the above IDEs, click on the link above.

Contents

0. Look at a Simple Example

Take a look at this simple example that plays sound when you click.

1. Upload a Sound File

The first step to adding sound to your game is to upload a sound file to the JavaWIDE site. Both the Sandbox and the Playground allow you to upload files up to 100K. Under the Toolbox on the left menu, click on Upload file. Select the audio file you would like to play in your game. At present, only wav files are supported.

Be sure to remember the exact name of the file you are uploading and be aware that JavaWIDE typically capitalizes the names of all files. You will need to be able to type in the exact name of the file in the following step.

2. Initialize a Sound Instance Variable

In your class, put in the following line of code:

Sound sound=new Sound("YourSound.wav");

where you replace YourSound.wav with the exact name of the file you uploaded in step 1.

Initialize each sound only once. Once initialized, you can play the sound repeatedly.

3. Play the Sound

Once you create the sound, there are various ways to play it:

sound.play(); plays the sound with equal balance between left and right speakers
sound.play(0); plays the sound completely on the left
sound.play(1); plays the sound completely on the right
sound.play(0.25); plays the sound mostly on the left but some on the right
sound.loop(); loops the sound
sound.stopLooping(); plays the sound until it completes but does not loop again
sound.stop(); stops the sound entirely

4. Be sure to Turn the Sound On

By default, games are muted to start with. If you want to turn the sound on by default, enter the following line in your startGame method:

toggleAudible();

Players can also turn the sound off and on via the button at the bottom of the game.





Views
Personal tools