diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-29 16:16:54 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-29 16:16:54 +0100 |
commit | 79568e3653a4dfb06d82e45949d4664e950cd4d3 (patch) | |
tree | f680f08227718f7242d97b58a2be1ce07937cb64 /core/src/ch/asynk/tankontank/engine | |
parent | 0dcfb59d471d7c1ef5767c546983fe68b963ee62 (diff) | |
download | RustAndDust-79568e3653a4dfb06d82e45949d4664e950cd4d3.zip RustAndDust-79568e3653a4dfb06d82e45949d4664e950cd4d3.tar.gz |
add SoundAnimation
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) + { + } +} |