Class SoundSource
java.lang.Object
de.gurkenlabs.litiengine.entities.Entity
de.gurkenlabs.litiengine.entities.SoundSource
- All Implemented Interfaces:
EntityRenderedListener
,EntityRenderListener
,IEntity
,Tweenable
,java.util.EventListener
public class SoundSource
extends Entity
This is an Entity that can play or loop ambient sound effects within a given range and with a given volume.
Field Summary
Constructor Summary
Constructors Constructor Description SoundSource()
An empty constructor that just calls the super constructor ofEntity
.SoundSource(double x, double y)
Initialize a SoundSource at a certain location.SoundSource(double x, double y, double width, double height)
Initialize a SoundSource at a certain location with a given size.SoundSource(Sound sound)
Initialize a SoundSource with a Sound.SoundSource(java.lang.String name)
Initialize a SoundSource with the name of a sound which will then be fetched from theResources.sounds()
.Method Summary
Modifier and Type Method Description SFXPlayback
getPlayback()
The playback used for playing the sound.int
getRange()
The range in pixels for which the sound can be heard.Sound
getSound()
The sound to be played.java.lang.String
getSoundName()
The name of the currently set sound.float
getVolume()
Get the volume modifier.boolean
isLoop()
Boolean determining if the sound is looped or only played back once.void
pause()
Pauses the current playback.void
play()
Starts a new playback in the SoundEngine and saves a reference to it in the SoundSource instance.void
resume()
Resumes the current playback if it was paused.void
setLoop(boolean loop)
Toggles looping for the sound playback.void
setRange(int range)
Sets the range in pixels for which the sound can be heard.void
setSound(Sound sound)
Sets the sound to be played.void
setSound(java.lang.String name)
Sets the sound by fetching a sound resource with a given name.void
setVolume(float volume)
Set the volume modifier.void
stop()
Cancels the current playback.Methods inherited from class de.gurkenlabs.litiengine.entities.Entity
actions, addController, addEntityRenderListener, addListener, addTag, addTransformListener, animations, attachControllers, behavior, canRender, detachControllers, getAngle, getBoundingBox, getCenter, getController, getControllers, getEnvironment, getHeight, getLocation, getMapId, getName, getProperties, getRenderType, getTags, getTweenValues, getWidth, getX, getY, hasTag, isLoaded, isVisible, loaded, onMessage, onMessage, onRendered, perform, register, removed, removeListener, removeListener, removeListener, removeListener, removeListener, removeTag, rendered, rendering, renderWithLayer, sendMessage, setAngle, setController, setHeight, setLocation, setLocation, setMapId, setName, setRenderType, setRenderWithLayer, setSize, setTweenValues, setVisible, setWidth, setX, setY, toString
Constructor Details
SoundSource
public SoundSource()An empty constructor that just calls the super constructor ofEntity
.SoundSource
Initialize a SoundSource with a Sound.- Parameters:
sound
- The sound used for playback
SoundSource
public SoundSource(java.lang.String name)Initialize a SoundSource with the name of a sound which will then be fetched from theResources.sounds()
.- Parameters:
name
- The name of the sound used for playback- See Also:
ResourcesContainer.get(String)
SoundSource
public SoundSource(double x, double y)Initialize a SoundSource at a certain location.- Parameters:
x
- The x coordinatey
- The y coordinate
SoundSource
public SoundSource(double x, double y, double width, double height)Initialize a SoundSource at a certain location with a given size. The size is irrelevant for the sound playback.- Parameters:
x
- The x coordinatey
- The y coordinatewidth
- The entity widthheight
- The entity height
Method Details
getVolume
public float getVolume()Get the volume modifier. The volume modifier is multiplied with the global sound volume defined bySoundConfiguration.getSoundVolume()
.- Returns:
- a float determining how much louder or quieter the sound is played back. 1.0 is the standard playback volume.
setVolume
public void setVolume(float volume)Set the volume modifier. The volume modifier is multiplied with the global sound volume defined bySoundConfiguration.getSoundVolume()
.- Parameters:
volume
- a float determining how much louder or quieter the sound is played back. 1.0 is the standard playback volume.
isLoop
public boolean isLoop()Boolean determining if the sound is looped or only played back once.- Returns:
true
, if the sound is looped when callingplay()
.false
, if it is played back just once.
setLoop
public void setLoop(boolean loop)Toggles looping for the sound playback.- Parameters:
loop
-true
, if the sound should be looped when callingplay()
.false
, if it should be played back just once.
getSound
The sound to be played.- Returns:
- the sound instance used for playback.
getPlayback
The playback used for playing the sound.- Returns:
- the playback instance.
getSoundName
public java.lang.String getSoundName()The name of the currently set sound.- Returns:
- A String containing the sound name.
getRange
public int getRange()The range in pixels for which the sound can be heard.- Returns:
- an
int
representing the range in pixels.
setRange
public void setRange(int range)Sets the range in pixels for which the sound can be heard.- Parameters:
range
- anint
representing the range in pixels.
setSound
public void setSound(java.lang.String name)Sets the sound by fetching a sound resource with a given name.- Parameters:
name
- The name of the Sound resource.- See Also:
ResourcesContainer.get(String)
setSound
Sets the sound to be played.- Parameters:
sound
- The sound to be played
play
public void play()Starts a new playback in the SoundEngine and saves a reference to it in the SoundSource instance. The playback reference can be called withgetPlayback()
.pause
public void pause()Pauses the current playback.- See Also:
SoundPlayback.pausePlayback()
resume
public void resume()Resumes the current playback if it was paused.- See Also:
SoundPlayback.resumePlayback()
stop
public void stop()Cancels the current playback.- See Also:
SoundPlayback.cancel()