2007-03-15 19:52:28 +00:00
|
|
|
package ei.engine.sound;
|
|
|
|
|
|
|
|
|
|
import ei.engine.scene.Entity;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A sound that can be played through OpenAL
|
|
|
|
|
*
|
|
|
|
|
* @author Kevin Glass
|
|
|
|
|
*/
|
|
|
|
|
public class Sound extends Entity{
|
|
|
|
|
/** The buffer containing the sound */
|
|
|
|
|
private int buffer;
|
2007-03-16 19:16:00 +00:00
|
|
|
private int source;
|
|
|
|
|
|
2007-03-15 19:52:28 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new sound
|
|
|
|
|
*
|
|
|
|
|
* @param name The name of the sound
|
|
|
|
|
* @param ref the path to the sound file
|
|
|
|
|
*/
|
|
|
|
|
public Sound(String name, String ref) {
|
|
|
|
|
super(name);
|
2007-03-16 19:16:00 +00:00
|
|
|
this.buffer = SoundLoader.getInstnace().loadSound(ref);
|
2007-03-15 19:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Play this sound as a sound effect
|
|
|
|
|
*/
|
2007-03-15 23:29:55 +00:00
|
|
|
public void play() {
|
2007-03-16 19:16:00 +00:00
|
|
|
source = SoundLoader.getInstnace().playSound(buffer, true);
|
|
|
|
|
update();
|
2007-03-15 23:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loop this sound
|
|
|
|
|
*/
|
|
|
|
|
public void loop() {
|
2007-03-16 19:16:00 +00:00
|
|
|
SoundLoader.getInstnace().playSound(buffer, true);
|
|
|
|
|
update();
|
2007-03-15 19:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void update() {
|
|
|
|
|
//AL10.alSource(source.get(0), AL10.AL_POSITION, sourcePos);
|
2007-03-16 19:16:00 +00:00
|
|
|
SoundLoader.getInstnace().setSoundLocation(
|
|
|
|
|
source, getLocation().getX(),getLocation().getY(),0);
|
|
|
|
|
|
2007-03-15 19:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* unimplamented method
|
|
|
|
|
*/
|
|
|
|
|
public void render() {}
|
|
|
|
|
}
|