O'Reilly logo

Haxe Game Development Essentials by Jeremy McCurdy

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

Adding gameplay sounds

Finally, we're going to set up and play our gameplay sounds. Since these sounds are going to get played frequently, we're going to load and store them so that they can be reused instead of being loaded every time they're needed.

This will also prevent the game from sounding overwhelming as there will only be one of any given type of effect playing at a time.

Creating variables

Let's start by making variables to store our gameplay sounds. In SoundManager, add these variables before any function calls:

private var shootSound:FlxSound;
private var damageSound:FlxSound;
private var explosion1Sound:FlxSound;
private var explosion2Sound:FlxSound;

These variables are of the FlxSound type. This class represents a sound that's loaded ...

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