Class SoundEngine



  • public class SoundEngine
    extends java.lang.Object
    Manages the sounds in the game world.
    • Constructor Summary

      Constructors 
      Constructor Description
      SoundEngine​()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose​()
      disposes the sounds. if you dispose the sounds they do not play if you reload a game. so stop them instead
      void disposeMusic​()  
      float getMusicLoudness​()  
      GameView getView​()  
      protected float getVolume​(Position pos)
      calculates the volume of a sound based on the positon in the game world.
      boolean isMusicPlaying​()
      Check if music is playing
      void loadRegisterIGSounds​()
      loads and registers the ig-sounds
      long loop​(java.lang.String identifier)
      playing Loops a sound.
      long loop​(java.lang.String identifier, Position pos)
      Starts playing a loop.
      void pauseMusic​()  
      void play​(java.lang.String identifier)  
      long play​(java.lang.String identifier, float volume)
      *
      long play​(java.lang.String identifier, float volume, float pitch)
      *
      long play​(java.lang.String identifier, float volume, float pitch, float pan)
      *
      void play​(java.lang.String identifier, Position pos)
      Plays sound with decreasing volume depending on distance.
      void play​(java.lang.String identifier, Position pos, float volume)
      Plays sound with decreasing volume depending on distance.
      void register​(java.lang.String identifier, java.lang.String path)
      Registers a sound.
      void setMusic​(java.lang.String path)
      Loads new music and plays them if a loudness is set.
      void setView​(GameView view)
      Set the gameplay view to calcualte sound based on the gameplay.
      void setVolume​(java.lang.String identifier, long instance, float volume)
      Set the volume of a playing instance.
      void stop​(java.lang.String identifier)
      Stops all instances of this sound.
      void stop​(java.lang.String identifier, long instance)
      Stops a specifiy instance of the sound.
      void stopEverySound​()  
      void update​(float dt)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SoundEngine

        public SoundEngine​()
    • Method Detail

      • loadRegisterIGSounds

        public void loadRegisterIGSounds​()
        loads and registers the ig-sounds
      • register

        public void register​(java.lang.String identifier,
                             java.lang.String path)
        Registers a sound. The sound must be loaded via asset manager. You can not register a sound twice.
        Parameters:
        identifier - name of sound
        path - path of the sound
      • play

        public void play​(java.lang.String identifier)
        Parameters:
        identifier - name of sound
      • play

        public void play​(java.lang.String identifier,
                         Position pos)
        Plays sound with decreasing volume depending on distance.
        Parameters:
        identifier - name of sound
        pos - the position of the sound in the world. if it is null then play at center
      • play

        public void play​(java.lang.String identifier,
                         Position pos,
                         float volume)
        Plays sound with decreasing volume depending on distance.
        Parameters:
        identifier - name of sound
        pos - the position of the sound in the world. if it is null then play at center
        volume - default is 1
      • play

        public long play​(java.lang.String identifier,
                         float volume)
        *
        Parameters:
        identifier - name of sound
        volume - default is 1
        Returns:
      • play

        public long play​(java.lang.String identifier,
                         float volume,
                         float pitch)
        *
        Parameters:
        identifier - name of sound
        volume -
        pitch - the pitch multiplier, 1 == default, >1 == faster, 1 == slower, the value has to be between 0.5 and 2.0
        Returns:
      • play

        public long play​(java.lang.String identifier,
                         float volume,
                         float pitch,
                         float pan)
        *
        Parameters:
        identifier - name of sound
        volume - the volume in the range [0,1]
        pitch - the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
        pan - panning in the range -1 (full left) to 1 (full right). 0 is center position.
        Returns:
      • loop

        public long loop​(java.lang.String identifier)
        playing Loops a sound.
        Parameters:
        identifier - name of sound
        Returns:
        the instance id
      • loop

        public long loop​(java.lang.String identifier,
                         Position pos)
        Starts playing a loop. If already playing will start another instance
        Parameters:
        identifier - name of sound
        pos - the position of the sound in the game world. Should be a reference to the position of the object and no copy so that it updates itself.
        Returns:
        the instance id
      • stop

        public void stop​(java.lang.String identifier)
        Stops all instances of this sound.
        Parameters:
        identifier - name of sound
      • stop

        public void stop​(java.lang.String identifier,
                         long instance)
        Stops a specifiy instance of the sound.
        Parameters:
        identifier - name of sound
        instance - the instance returned by play(String) or loop(String).
        See Also:
        Sound.stop()
      • stopEverySound

        public void stopEverySound​()
      • setVolume

        public void setVolume​(java.lang.String identifier,
                              long instance,
                              float volume)
        Set the volume of a playing instance.
        Parameters:
        identifier - name of sound
        instance - the instance returned by play(String) or loop(String).
        volume -
      • update

        public void update​(float dt)
        Parameters:
        dt -
      • dispose

        public void dispose​()
        disposes the sounds. if you dispose the sounds they do not play if you reload a game. so stop them instead
      • getVolume

        protected float getVolume​(Position pos)
        calculates the volume of a sound based on the positon in the game world. Compares to cameras.
        Parameters:
        pos - position in the world.
        Returns:
        multiplied with the settings for the volume
      • setView

        public void setView​(GameView view)
        Set the gameplay view to calcualte sound based on the gameplay.
        Parameters:
        view -
      • getMusicLoudness

        public float getMusicLoudness​()
        Returns:
      • setMusic

        public void setMusic​(java.lang.String path)
        Loads new music and plays them if a loudness is set.
        Parameters:
        path -
      • isMusicPlaying

        public boolean isMusicPlaying​()
        Check if music is playing
        Returns:
        true if music is playing
      • disposeMusic

        public void disposeMusic​()
      • pauseMusic

        public void pauseMusic​()
      • getView

        public GameView getView​()
        Returns: