Class SoundEngine
- java.lang.Object
-
- com.bombinggames.wurfelengine.soundengine.SoundEngine
-
public class SoundEngine extends java.lang.ObjectManages the sounds in the game world.
-
-
Constructor Summary
Constructors Constructor Description SoundEngine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()disposes the sounds. if you dispose the sounds they do not play if you reload a game. so stop them insteadvoiddisposeMusic()floatgetMusicLoudness()GameViewgetView()protected floatgetVolume(Position pos)calculates the volume of a sound based on the positon in the game world.booleanisMusicPlaying()Check if music is playingvoidloadRegisterIGSounds()loads and registers the ig-soundslongloop(java.lang.String identifier)playing Loops a sound.longloop(java.lang.String identifier, Position pos)Starts playing a loop.voidpauseMusic()voidplay(java.lang.String identifier)longplay(java.lang.String identifier, float volume)*longplay(java.lang.String identifier, float volume, float pitch)*longplay(java.lang.String identifier, float volume, float pitch, float pan)*voidplay(java.lang.String identifier, Position pos)Plays sound with decreasing volume depending on distance.voidplay(java.lang.String identifier, Position pos, float volume)Plays sound with decreasing volume depending on distance.voidregister(java.lang.String identifier, java.lang.String path)Registers a sound.voidsetMusic(java.lang.String path)Loads new music and plays them if a loudness is set.voidsetView(GameView view)Set the gameplay view to calcualte sound based on the gameplay.voidsetVolume(java.lang.String identifier, long instance, float volume)Set the volume of a playing instance.voidstop(java.lang.String identifier)Stops all instances of this sound.voidstop(java.lang.String identifier, long instance)Stops a specifiy instance of the sound.voidstopEverySound()voidupdate(float dt)
-
-
-
Method Detail
-
loadRegisterIGSounds
public void loadRegisterIGSounds()
loads and registers the ig-sounds
-
register
public void register(java.lang.String identifier, java.lang.String path)Registers a sound. The sound must be loaded via asset manager. You can not register a sound twice.- Parameters:
identifier- name of soundpath- path of the sound
-
play
public void play(java.lang.String identifier)
- Parameters:
identifier- name of sound
-
play
public void play(java.lang.String identifier, Position pos)Plays sound with decreasing volume depending on distance.- Parameters:
identifier- name of soundpos- the position of the sound in the world. if it is null then play at center
-
play
public void play(java.lang.String identifier, Position pos, float volume)Plays sound with decreasing volume depending on distance.- Parameters:
identifier- name of soundpos- the position of the sound in the world. if it is null then play at centervolume- default is 1
-
play
public long play(java.lang.String identifier, float volume)*- Parameters:
identifier- name of soundvolume- default is 1- Returns:
-
play
public long play(java.lang.String identifier, float volume, float pitch)*- Parameters:
identifier- name of soundvolume-pitch- the pitch multiplier, 1 == default, >1 == faster, 1 == slower, the value has to be between 0.5 and 2.0- Returns:
-
play
public long play(java.lang.String identifier, float volume, float pitch, float pan)*- Parameters:
identifier- name of soundvolume- the volume in the range [0,1]pitch- the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0pan- panning in the range -1 (full left) to 1 (full right). 0 is center position.- Returns:
-
loop
public long loop(java.lang.String identifier)
playing Loops a sound.- Parameters:
identifier- name of sound- Returns:
- the instance id
-
loop
public long loop(java.lang.String identifier, Position pos)Starts playing a loop. If already playing will start another instance- Parameters:
identifier- name of soundpos- the position of the sound in the game world. Should be a reference to the position of the object and no copy so that it updates itself.- Returns:
- the instance id
-
stop
public void stop(java.lang.String identifier)
Stops all instances of this sound.- Parameters:
identifier- name of sound
-
stop
public void stop(java.lang.String identifier, long instance)Stops a specifiy instance of the sound.- Parameters:
identifier- name of soundinstance- the instance returned byplay(String)orloop(String).- See Also:
Sound.stop()
-
stopEverySound
public void stopEverySound()
-
setVolume
public void setVolume(java.lang.String identifier, long instance, float volume)Set the volume of a playing instance.- Parameters:
identifier- name of soundinstance- the instance returned byplay(String)orloop(String).volume-
-
update
public void update(float dt)
- Parameters:
dt-
-
dispose
public void dispose()
disposes the sounds. if you dispose the sounds they do not play if you reload a game. so stop them instead
-
getVolume
protected float getVolume(Position pos)
calculates the volume of a sound based on the positon in the game world. Compares to cameras.- Parameters:
pos- position in the world.- Returns:
- multiplied with the settings for the volume
-
setView
public void setView(GameView view)
Set the gameplay view to calcualte sound based on the gameplay.- Parameters:
view-
-
getMusicLoudness
public float getMusicLoudness()
- Returns:
-
setMusic
public void setMusic(java.lang.String path)
Loads new music and plays them if a loudness is set.- Parameters:
path-
-
isMusicPlaying
public boolean isMusicPlaying()
Check if music is playing- Returns:
- true if music is playing
-
disposeMusic
public void disposeMusic()
-
pauseMusic
public void pauseMusic()
-
getView
public GameView getView()
- Returns:
-
-