Hello. I am currently attempting to add sound effects to my game. I decided to keep the implementation of this in an AudioManager class on which I could just call playSound() from other parts of my program. However, I am having an issue with AudioNodes. From messing around with it, I have figured that I can only call the AudioNode constructor once, and only once, even by putting it on different references. When I attempt to construct another AudioNode, the game stops responding.
I am simply at a loss of what to do. I tried looking at helloAudio but to no avail.
[java]
public class AudioManager
{
private Main app;
private AudioNode book;
private AudioNode cabinet;
private AudioNode correct;
private AudioNode door;
private AudioNode incorrect;
private AudioNode idCard;
private AudioNode select;
private AudioNode waterGulp;
public AudioManager(Main app)
{
this.app = app;
}
public void prepareAudio()
{
book = new AudioNode(app.getAssetManager(), "Sounds/Book.ogg", false);
app.getRootNode().attachChild(book);
cabinet = new AudioNode(app.getAssetManager(), "Sounds/Cabinet.ogg", false);
app.getRootNode().attachChild(cabinet);
correct = new AudioNode(app.getAssetManager(), "Sounds/Correct.ogg", false);
app.getRootNode().attachChild(correct);
door = new AudioNode(app.getAssetManager(), "Sounds/Door.ogg", false);
app.getRootNode().attachChild(door);
idCard = new AudioNode(app.getAssetManager(), "Sounds/IDCard.ogg", false);
app.getRootNode().attachChild(idCard);
incorrect = new AudioNode(app.getAssetManager(), "Sounds/Incorrect.ogg", false);
app.getRootNode().attachChild(incorrect);
select = new AudioNode(app.getAssetManager(), "Sounds/Select.ogg", false);
app.getRootNode().attachChild(select);
waterGulp = new AudioNode(app.getAssetManager(), "Sounds/Water Gulp.ogg", false);
app.getRootNode().attachChild(waterGulp);
}
public void playBook()
{
book.play();
}
public void playCabinet()
{
cabinet.play();
}
public void playCorrect()
{
correct.play();
}
public void playDoor()
{
door.play();
}
public void playIDCard()
{
idCard.play();
}
public void playIncorrect()
{
incorrect.play();
}
public void playSelect()
{
select.play();
}
public void playWaterGulp()
{
waterGulp.play();
}
}
The constructor is called, then prepareAudio(), then each time I want a sound played I call the playSound() methods.