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 ...

Get Haxe Game Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.