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.
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 into memory.
Navigate into the constructor. In there, we're going to load and set up the sounds:
shootSound = FlxG.sound.load(Sounds.SOUND_SHOOT, Sounds.VOLUME_SHOOT); shootSound.persist = true; damageSound = FlxG.sound.load(Sounds.SOUND_DAMAGE, Sounds...