fixed bug when playing rocket audio to not produce an AudioRender error

This commit is contained in:
Fleischer Hanno hanno.fleischer@unibw.de
2024-10-13 11:53:24 +02:00
parent 9e591e37c3
commit f8e97266d5
3 changed files with 9 additions and 16 deletions

View File

@@ -83,10 +83,10 @@ public void setEnabled(boolean enabled) {
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app = (BattleshipApp) app;
shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav", 1); //NON-NLS
splashSound = loadSound(app, "Sound/Effects/splash.wav", 2); //NON-NLS
explosionSound = loadSound(app, "Sound/Effects/explosion.wav",3); //NON-NLS
rocketSound = loadSound(app, "Sound/Effects/rocket.wav",4);
shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav"); //NON-NLS
splashSound = loadSound(app, "Sound/Effects/splash.wav"); //NON-NLS
explosionSound = loadSound(app, "Sound/Effects/explosion.wav"); //NON-NLS
rocketSound = loadSound(app, "Sound/Effects/rocket.wav");
volume = PREFERENCES.getFloat(SOUND_VOLUME_PREF, 1.0f);
}
@@ -98,12 +98,11 @@ public void initialize(AppStateManager stateManager, Application app) {
* @param name The name of the sound file.
* @return The loaded AudioNode.
*/
private AudioNode loadSound(Application app, String name, int channel) {
private AudioNode loadSound(Application app, String name) {
try {
final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
sound.setLooping(false);
sound.setPositional(false);
sound.setChannel(channel);
return sound;
}
catch (AssetLoadException | AssetNotFoundException ex) {

View File

@@ -1,6 +1,5 @@
package pp.battleship.game.client;
import pp.battleship.message.client.AnimationEndMessage;
import pp.battleship.message.server.EffectMessage;
import pp.battleship.message.server.SwitchBattleState;
import pp.battleship.model.IntPoint;
@@ -9,7 +8,7 @@
import pp.battleship.notification.Music;
import pp.battleship.notification.Sound;
public class AnimatonState extends ClientState {
public class AnimationState extends ClientState {
private boolean myTurn;
/**
@@ -19,15 +18,15 @@ public class AnimatonState extends ClientState {
* @param myTurn a boolean containing if it is the clients turn
* @param position the position a shell should be created
*/
public AnimatonState(ClientGameLogic logic, boolean myTurn, IntPoint position) {
public AnimationState(ClientGameLogic logic, boolean myTurn, IntPoint position) {
super(logic);
logic.playMusic(Music.BATTLE_THEME);
logic.playSound(Sound.ROCKET_FIRED);
this.myTurn = myTurn;
if(myTurn) {
logic.getOpponentMap().add(new Shell(position));
}else {
logic.getOwnMap().add(new Shell(position));
logic.playSound(Sound.ROCKET_FIRED);
}
}

View File

@@ -9,13 +9,8 @@
import pp.battleship.message.client.ShootMessage;
import pp.battleship.message.server.AnimationStartMessage;
import pp.battleship.message.server.EffectMessage;
import pp.battleship.model.IntPoint;
import pp.battleship.model.ShipMap;
import pp.battleship.notification.Music;
import pp.battleship.notification.Sound;
import java.lang.System.Logger.Level;
/**
* Represents the state of the client where players take turns to attack each other's ships.
@@ -55,6 +50,6 @@ else if (logic.getOpponentMap().isValid(pos))
@Override
public void receivedAnimationStart(AnimationStartMessage msg){
logic.setState(new AnimatonState(logic, msg.isMyTurn(), msg.getPosition()));
logic.setState(new AnimationState(logic, msg.isMyTurn(), msg.getPosition()));
}
}