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.
  • Constructor Details

    • SoundSource

      public SoundSource()
      An empty constructor that just calls the super constructor of Entity.
    • SoundSource

      public SoundSource​(Sound sound)
      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 the Resources.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 coordinate
      y - 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 coordinate
      y - The y coordinate
      width - The entity width
      height - The entity height
  • Method Details

    • getVolume

      public float getVolume()
      Get the volume modifier. The volume modifier is multiplied with the global sound volume defined by SoundConfiguration.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 by SoundConfiguration.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 calling play(). 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 calling play(). false, if it should be played back just once.
    • getSound

      public Sound getSound()
      The sound to be played.
      Returns:
      the sound instance used for playback.
    • getPlayback

      public SFXPlayback 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 - an int 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

      public void setSound​(Sound sound)
      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 with getPlayback().
      See Also:
      SoundEngine.playSound(Sound, IEntity, boolean, int, float), SFXPlayback
    • 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()