v0.8.2: added delayed SFX functionality, used it to improve hit_strong
This commit is contained in:
@@ -251,7 +251,8 @@ public class Game implements ApplicationListener {
|
||||
Game.realTime = TimeUtils.millis();
|
||||
|
||||
inputHandler.processAllEvents();
|
||||
|
||||
|
||||
Sample.INSTANCE.update();
|
||||
scene.update();
|
||||
Camera.updateAll();
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ package com.watabou.noosa.audio;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.watabou.noosa.Game;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public enum Sample {
|
||||
|
||||
@@ -42,6 +44,7 @@ public enum Sample {
|
||||
}
|
||||
|
||||
ids.clear();
|
||||
delayedSFX.clear();
|
||||
|
||||
}
|
||||
|
||||
@@ -104,6 +107,54 @@ public enum Sample {
|
||||
}
|
||||
}
|
||||
|
||||
private class DelayedSoundEffect{
|
||||
Object id;
|
||||
float delay;
|
||||
|
||||
float leftVol;
|
||||
float rightVol;
|
||||
float pitch;
|
||||
}
|
||||
|
||||
private static HashSet<DelayedSoundEffect> delayedSFX = new HashSet<>();
|
||||
|
||||
public void playDelayed( Object id, float delay ){
|
||||
playDelayed( id, delay, 1 );
|
||||
}
|
||||
|
||||
public void playDelayed( Object id, float delay, float volume ) {
|
||||
playDelayed( id, delay, volume, volume, 1 );
|
||||
}
|
||||
|
||||
public void playDelayed( Object id, float delay, float volume, float pitch ) {
|
||||
playDelayed( id, delay, volume, volume, pitch );
|
||||
}
|
||||
|
||||
public synchronized void playDelayed( Object id, float delay, float leftVolume, float rightVolume, float pitch ) {
|
||||
if (delay <= 0) {
|
||||
play(id, leftVolume, rightVolume, pitch);
|
||||
return;
|
||||
}
|
||||
DelayedSoundEffect sfx = new DelayedSoundEffect();
|
||||
sfx.id = id;
|
||||
sfx.delay = delay;
|
||||
sfx.leftVol = leftVolume;
|
||||
sfx.rightVol = rightVolume;
|
||||
sfx.pitch = pitch;
|
||||
delayedSFX.add(sfx);
|
||||
}
|
||||
|
||||
public synchronized void update(){
|
||||
if (delayedSFX.isEmpty()) return;
|
||||
for (DelayedSoundEffect sfx : delayedSFX.toArray(new DelayedSoundEffect[0])){
|
||||
sfx.delay -= Game.elapsed;
|
||||
if (sfx.delay <= 0){
|
||||
delayedSFX.remove(sfx);
|
||||
play(sfx.id, sfx.leftVol, sfx.rightVol, sfx.pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void enable( boolean value ) {
|
||||
enabled = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user