Class BackgroundSoundComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.BackgroundSoundComponent

public class BackgroundSoundComponent extends Component
Reusable sound component to create background music Loads, plays and unloads music automatically. Note: Maps files to the Music class and not the Sound class.
  • Constructor Details

    • BackgroundSoundComponent

      public BackgroundSoundComponent(String backgroundMusic, float volume, boolean looping)
      Parameters:
      backgroundMusic - set the background music
      volume - set the volume
      looping - set the looping to true or false

      Example:

       
         addComponent(new BackgroundSoundComponent("sounds/MenuSong-Overcast.mp3", 0.5f, true));
       
  • Method Details

    • create

      public void create()
      Description copied from class: Component
      Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.
      Overrides:
      create in class Component
    • playSound

      public void playSound()
      Play the background music
    • dispose

      public void dispose()
      Description copied from class: Component
      Called when the component is disposed. Dispose of any internal resources here.
      Overrides:
      dispose in class Component
    • stopSound

      public void stopSound()
      Stop playing the music