Sprint 4: Player SFX Management - UQdeco2800/2021-studio-6 GitHub Wiki

Motivation

To allow the user to fully comprehend the story and gameplay, it's important to immerse the user within the environment. Music and sound effects are a key way to do this, while also adding feedback for initiated actions. This project focuses on the sound effects, initiated by actions the player takes within the game.

Overview

Originally, sound effects were implemented as direct function calls (.getAsset() and .play()) to libGDX's ResourceService for sound effects (game engine docs here). However, Team 5 took the initiative to consolidate this down to a central component for all NPC (enemy) sound effects, as to maintain a consistent store of asset file path and consistent volume. We shall follow this structure with the player sound effects, creating PlayerSoundComponent.

Some benefits of this are:

  • All file paths are in one location set in the entity/*Factory files.
  • Loading assets is in the same file as the ResourceService initialization, no problems with unloaded service.
  • Generalizing the interface for different asset variants for each level.
  • Consistent sound effect parameters (volume, looping, sound asset).

Disadvantages are:

  • Somewhat removes the asynchronous nature of calling for a sound effect, requires the PlayerSoundComponent to be loaded.
  • Removes the option to customize parameters for each action.

Usage

To add new sound effects to the game, implement the following (replace %SoundName% with asset's name, ie. useBandage):

  • Instance Variable (private Sound %SoundName%;)
  • Asset Loader (public void set%SoundName%(Sound %SoundName%) { this.%SoundName% = %SoundName%; })
  • Sound Player
public void play%SoundName%() {
    if (this.%SoundName% != null) {
        long soundId = this.%SoundName%.play();
        this.%SoundName%.setVolume(soundId, this.volume);
    }
}