Class SoundSource
java.lang.Object
de.gurkenlabs.litiengine.entities.Entity
de.gurkenlabs.litiengine.entities.SoundSource
- All Implemented Interfaces:
EntityRenderedListener
,EntityRenderListener
,IEntity
,Tweenable
,EventListener
This is an Entity that can play or loop ambient sound effects within a given range and with a given volume.
-
Field Summary
Fields inherited from class de.gurkenlabs.litiengine.entities.Entity
ANY_MESSAGE
-
Constructor Summary
ConstructorsConstructorDescriptionAn 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
(String name) Initialize a SoundSource with the name of a sound which will then be fetched from theResources.sounds()
. -
Method Summary
Modifier and TypeMethodDescriptionThe playback used for playing the sound.int
getRange()
The range in pixels for which the sound can be heard.getSound()
The sound to be played.The name of the currently set sound.float
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
Sets the sound to be played.void
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
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:
-
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
-
getPlayback
The playback used for playing the sound.- Returns:
- the playback instance.
-
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
Sets the sound by fetching a sound resource with a given name.- Parameters:
name
- The name of the Sound resource.- See Also:
-
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()
.- See Also:
-
pause
public void pause()Pauses the current playback.- See Also:
-
resume
public void resume()Resumes the current playback if it was paused.- See Also:
-
stop
public void stop()Cancels the current playback.- See Also:
-