Package com.deco2800.game.components
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.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BackgroundSoundComponent(java.lang.String backgroundMusic)
BackgroundSoundComponent(java.lang.String backgroundMusic, float volume)
BackgroundSoundComponent(java.lang.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
public BackgroundSoundComponent(java.lang.String backgroundMusic)- Parameters:
backgroundMusic
- the background music path Example:addComponent(new BackgroundSoundComponent("sounds/achievementBgm.mp3"));
-
BackgroundSoundComponent
public BackgroundSoundComponent(java.lang.String backgroundMusic, float volume)- Parameters:
backgroundMusic
- the background music pathvolume
- the volume to be setExample:
addComponent(new BackgroundSoundComponent("sounds/achievementBgm.mp3", 0.5f));
-
BackgroundSoundComponent
public BackgroundSoundComponent(java.lang.String backgroundMusic, float volume, boolean looping)- Parameters:
backgroundMusic
- set the background musicvolume
- set the volumelooping
- set the looping to true or falseExample:
addComponent(new BackgroundSoundComponent("sounds/achievementBgm.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
-