diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank/engine')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/gfx/animations/SoundAnimation.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/gfx/animations/SoundAnimation.java b/core/src/ch/asynk/tankontank/engine/gfx/animations/SoundAnimation.java new file mode 100644 index 0000000..aaa7787 --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/gfx/animations/SoundAnimation.java @@ -0,0 +1,81 @@ +package ch.asynk.tankontank.engine.gfx.animations; + +import com.badlogic.gdx.utils.Pool; +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +public class SoundAnimation extends TimedAnimation +{ + public enum Action + { + FADE_IN, + FADE_OUT + }; + + private Sound sound; + private long soundId; + private Action action; + + private static final Pool<SoundAnimation> soundAnimationPool = new Pool<SoundAnimation>() { + @Override + protected SoundAnimation newObject() { + return new SoundAnimation(); + } + }; + + public static SoundAnimation get(Action action, Sound sound, long soundId, float duration) + { + SoundAnimation a = soundAnimationPool.obtain(); + + a.action = action; + a.sound = sound; + a.soundId = soundId; + a.duration = duration; + + return a; + } + + @Override + public void dispose() + { + soundAnimationPool.free(this); + } + + @Override + protected void begin() + { + } + + @Override + protected void end() + { + dispose(); + } + + @Override + protected void update(float percent) + { + float v; + switch(action) { + case FADE_IN: + v = ( 1.0f * percent); + sound.setVolume(soundId, v); + break; + case FADE_OUT: + v = (1.0f - ( 1.0f * percent)); + sound.setVolume(soundId, v); + break; + } + } + + @Override + public void draw(Batch batch) + { + } + + @Override + public void drawDebug(ShapeRenderer debugShapes) + { + } +} |