Package com.deco2800.game.components
Class BackgroundSoundComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.BackgroundSoundComponent
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.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionBackgroundSoundComponent
(String backgroundMusic, float volume, boolean looping) -
Method Summary
Methods inherited from class com.deco2800.game.components.Component
earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
BackgroundSoundComponent
- Parameters:
backgroundMusic
- set the background musicvolume
- set the volumelooping
- set the looping to true or falseExample:
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. -
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. -
stopSound
public void stopSound()Stop playing the music
-