5. Play Sounds

1. Check the Sounds Folder

Sound files must be placed the 'sounds' folder of your Greenfoot project to be used in the game.

In the Component 2 exam of the WJEC / Eduqas 2016 specification, an audio file will be placed in the sounds folder already.

For this example game you can download the audio clips to the right and paste them into your sounds folder.

Click the audio icon to download a zip folder of the two sound files below. Copy the files into the sounds folder of your Greenfoot project.

2. Add the playSound Method

Add the code to play the sound at the same time as when the collectible object is removed.

The name of the file and its extension (e.g. .wav or .mp3) must be written in speech marks after the playSound method.

© CSNewbs 2021