public final class SoundEngine extends java.lang.Object implements IUpdateable, ILaunchable
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_DISTANCE |
Constructor and Description |
---|
SoundEngine()
Instantiates a new SoundEngine instance.
|
Modifier and Type | Method and Description |
---|---|
void |
fadeMusic(int time)
Fades out the music over the specified time, if playing.
|
void |
fadeMusic(int time,
java.lang.Runnable callback)
Fades out the music over the specified time, then calls the provided callback.
|
java.util.Collection<MusicPlayback> |
getAllMusic() |
float |
getMaxDistance()
Gets the maximum distance from the listener at which a sound source can
still be heard.
|
MusicPlayback |
getMusic()
Gets the "main" music that is playing.
|
void |
playMusic(Sound music) |
void |
playMusic(java.lang.String music) |
void |
playMusic(Track track)
Sets the currently playing track to the specified track.
|
void |
playMusic(Track track,
boolean restart)
Sets the currently playing track to the specified track.
|
void |
playMusic(Track track,
boolean restart,
boolean stop)
Plays the specified track.
|
SFXPlayback |
playSound(Sound sound)
Plays the specified sound with the volume configured in the SOUND config
with a center pan.
|
SFXPlayback |
playSound(Sound sound,
boolean loop)
Plays the specified sound with the volume configured in the SOUND config
with a center pan.
|
SFXPlayback |
playSound(Sound sound,
double x,
double y) |
SFXPlayback |
playSound(Sound sound,
double x,
double y,
boolean loop) |
SFXPlayback |
playSound(Sound sound,
IEntity entity)
Plays the specified sound and updates its volume and pan by the current
entity location in relation to the listener location.
|
SFXPlayback |
playSound(Sound sound,
IEntity entity,
boolean loop)
Plays the specified sound and updates its volume and pan by the current
entity location in relation to the listener location.
|
SFXPlayback |
playSound(Sound sound,
java.awt.geom.Point2D location)
Plays the specified sound at the specified location and updates the volume
and pan in relation to the listener location.
|
SFXPlayback |
playSound(Sound sound,
java.awt.geom.Point2D location,
boolean loop)
Plays the specified sound at the specified location and updates the volume
and pan in relation to the listener location.
|
SFXPlayback |
playSound(java.lang.String sound) |
SFXPlayback |
playSound(java.lang.String sound,
boolean loop) |
SFXPlayback |
playSound(java.lang.String sound,
double x,
double y) |
SFXPlayback |
playSound(java.lang.String sound,
double x,
double y,
boolean loop) |
SFXPlayback |
playSound(java.lang.String sound,
IEntity entity) |
SFXPlayback |
playSound(java.lang.String sound,
IEntity entity,
boolean loop) |
SFXPlayback |
playSound(java.lang.String sound,
java.awt.geom.Point2D location) |
SFXPlayback |
playSound(java.lang.String sound,
java.awt.geom.Point2D location,
boolean loop) |
void |
setListenerLocationCallback(java.util.function.Function<java.awt.geom.Point2D,java.awt.geom.Point2D> callback)
This method allows to set the callback that is used by the SoundEngine to
determine where the listener location is.
|
void |
setMaxDistance(float radius)
Sets the maximum distance from the listener at which a sound source can
still be heard.
|
void |
start()
Starts the operation of this instance.
|
void |
stopMusic()
Stops the playback of the current background music.
|
void |
terminate()
Terminates the operation of this instance.
|
void |
update()
This method is called by the game loop on all objects that need to update
their attributes.
|
public static final int DEFAULT_MAX_DISTANCE
public SoundEngine()
You should never call this manually! Instead use the Game.audio()
instance.
Game.audio()
public float getMaxDistance()
public void playMusic(java.lang.String music)
public void playMusic(Sound music)
public void playMusic(Track track)
track
- The track to playpublic void playMusic(Track track, boolean restart)
track
- The track to playrestart
- Whether to restart if the specified track is already playing, determined by Object.equals(Object)
public void playMusic(Track track, boolean restart, boolean stop)
track
- The track to playrestart
- Whether to restart if the specified track is already playing, determined by Object.equals(Object)
stop
- Whether to stop an existing track if presentpublic void fadeMusic(int time)
time
- The time in frames to make the existing music fade out for if presentpublic void fadeMusic(int time, java.lang.Runnable callback)
time
- The time in frames to make the existing music fade out for if presentcallback
- The callback for when the fade finishespublic MusicPlayback getMusic()
playMusic
, though if the music has been stopped it will be
null
.null
.public java.util.Collection<MusicPlayback> getAllMusic()
public SFXPlayback playSound(Sound sound, IEntity entity)
entity
- The entity at which location the sound should be played.sound
- The sound to play.SFXPlayback
instance that allows to further process
and control the played sound.public SFXPlayback playSound(java.lang.String sound, IEntity entity)
public SFXPlayback playSound(Sound sound, IEntity entity, boolean loop)
entity
- The entity at which location the sound should be played.sound
- The sound to play.loop
- Determines whether this playback should be looped or not.SFXPlayback
instance that allows to further process
and control the played sound.public SFXPlayback playSound(java.lang.String sound, IEntity entity, boolean loop)
public SFXPlayback playSound(Sound sound, java.awt.geom.Point2D location)
location
- The location at which to play the sound.sound
- The sound to play.SFXPlayback
instance that allows to further process
and control the played sound.public SFXPlayback playSound(java.lang.String sound, java.awt.geom.Point2D location)
public SFXPlayback playSound(Sound sound, double x, double y)
public SFXPlayback playSound(java.lang.String sound, double x, double y)
public SFXPlayback playSound(Sound sound, java.awt.geom.Point2D location, boolean loop)
location
- The location at which to play the sound.sound
- The sound to play.loop
- Determines whether this playback should be looped or not.SFXPlayback
instance that allows to further process
and control the played sound.public SFXPlayback playSound(java.lang.String sound, java.awt.geom.Point2D location, boolean loop)
public SFXPlayback playSound(Sound sound, double x, double y, boolean loop)
public SFXPlayback playSound(java.lang.String sound, double x, double y, boolean loop)
public SFXPlayback playSound(Sound sound)
sound
- The sound to play.SFXPlayback
instance that allows to further process
and control the played sound.public SFXPlayback playSound(java.lang.String sound)
public SFXPlayback playSound(Sound sound, boolean loop)
sound
- The sound to play.loop
- Determines whether this playback should be looped or not.SFXPlayback
instance that allows to further process
and control the played sound.public SFXPlayback playSound(java.lang.String sound, boolean loop)
public void setMaxDistance(float radius)
radius
- The maximum distance at which sounds can still be heard.public void stopMusic()
public void setListenerLocationCallback(java.util.function.Function<java.awt.geom.Point2D,java.awt.geom.Point2D> callback)
callback
- The callback that determines the location of the sound listener.public void start()
ILaunchable
start
in interface ILaunchable
public void terminate()
ILaunchable
terminate
in interface ILaunchable
public void update()
IUpdateable
update
in interface IUpdateable