(CSGC) Audio Lesson
Audio
Sounds are used in games to enhance gameplay. Sounds are used to signal different events such as introduction, winning, losing, or an achievement.
Greenfoot has a class called Greenfoot Sound for playing audio in Greenfoot. To be playable, the sound file must be located in the sounds folder inside the scenario folder. A Greenfoot Sound loads the audio from the sound file.
Most files of the following formats are supported: AIFF, AU, WAV, MP3 and MIDI.
Obtaining Sound Files
You can copy sounds from other Greenfoot projects or download sounds from various free sound libraries on the internet. You can also record your own sounds using a sound recording program. Many programs are available free on the internet.
Most files of the following formats are supported: AIFF, AU, WAV, MP3 and MIDI.
Methods in Greenfoot Sound
Using the Sound Methods
You must create a sound from the constructor before you can use a sound.
public GreenfootSound introSound = new GreenfootSound("intro.mp3");
In the FlyingBird program, an intro sound is played in a loop if the title screen is showing and the objects have not been added.
One the game starts, the intro sound is stopped using the stop() method.
[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION