From 79568e3653a4dfb06d82e45949d4664e950cd4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 29 Oct 2014 16:16:54 +0100 Subject: add SoundAnimation --- .../engine/gfx/animations/SoundAnimation.java | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 core/src/ch/asynk/tankontank/engine/gfx/animations/SoundAnimation.java 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 soundAnimationPool = new Pool() { + @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) + { + } +} -- cgit v1.1-2-g2b99