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 EntityThis 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 SFXPlaybackgetPlayback()The playback used for playing the sound.intgetRange()The range in pixels for which the sound can be heard.SoundgetSound()The sound to be played.java.lang.StringgetSoundName()The name of the currently set sound.floatgetVolume()Get the volume modifier.booleanisLoop()Boolean determining if the sound is looped or only played back once.voidpause()Pauses the current playback.voidplay()Starts a new playback in the SoundEngine and saves a reference to it in the SoundSource instance.voidresume()Resumes the current playback if it was paused.voidsetLoop(boolean loop)Toggles looping for the sound playback.voidsetRange(int range)Sets the range in pixels for which the sound can be heard.voidsetSound(Sound sound)Sets the sound to be played.voidsetSound(java.lang.String name)Sets the sound by fetching a sound resource with a given name.voidsetVolume(float volume)Set the volume modifier.voidstop()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
intrepresenting the range in pixels.
setRange
public void setRange(int range)Sets the range in pixels for which the sound can be heard.- Parameters:
range- anintrepresenting 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()
