New better sound support

This commit is contained in:
Ziver Koc 2007-03-16 19:16:00 +00:00
parent 47de3ed661
commit 635d756429
3 changed files with 131 additions and 52 deletions

View file

@ -1,9 +1,6 @@
package ei.engine.sound;
import java.io.IOException;
import ei.engine.scene.Entity;
import ei.engine.util.MultiPrintStream;
/**
* A sound that can be played through OpenAL
@ -13,7 +10,8 @@ import ei.engine.util.MultiPrintStream;
public class Sound extends Entity{
/** The buffer containing the sound */
private int buffer;
private int source;
/**
* Create a new sound
*
@ -22,30 +20,30 @@ public class Sound extends Entity{
*/
public Sound(String name, String ref) {
super(name);
try {
this.buffer = SoundLoader.getInstnace().loadSound(ref);
} catch (IOException e) {
MultiPrintStream.out.println("Unable to load sound: "+ref+" - "+e.getMessage());
e.printStackTrace();
}
this.buffer = SoundLoader.getInstnace().loadSound(ref);
}
/**
* Play this sound as a sound effect
*/
public void play() {
SoundLoader.getInstnace().playSound(buffer, getLocation(),false);
source = SoundLoader.getInstnace().playSound(buffer, true);
update();
}
/**
* Loop this sound
*/
public void loop() {
SoundLoader.getInstnace().playSound(buffer, getLocation(),true);
SoundLoader.getInstnace().playSound(buffer, true);
update();
}
public void update() {
//AL10.alSource(source.get(0), AL10.AL_POSITION, sourcePos);
SoundLoader.getInstnace().setSoundLocation(
source, getLocation().getX(),getLocation().getY(),0);
}
/**