1 musique par menu et une pour la game

This commit is contained in:
heurtet 2021-05-13 22:39:34 +02:00
parent ae2ab5b643
commit 037bbc7ce1
8 changed files with 45 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -12,6 +12,8 @@ public class SagittariusGame extends Game {
public static float G = 100;
public static boolean debugMode = true;
public static Music music;
public static boolean disableMusic= false;
public static float musicVolume= 0.5f;
public static boolean disableSounds = false;
public static float soundsVolume = 0.5f;
private static Game game;
@ -31,14 +33,6 @@ public class SagittariusGame extends Game {
@Override
public void create() {
// A welcome music is played
music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/Ghostrifter-Deflector.mp3"));
music.setLooping(true);
music.play();
// Default volume
music.setVolume(0.3f);
// We load the VisUI library
VisUI.load();

View file

@ -4,6 +4,8 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.scenes.scene2d.Stage;
import sagittarius.SagittariusGame;
import com.badlogic.gdx.Screen;
public abstract class BaseScreen implements Screen {
@ -42,6 +44,8 @@ public abstract class BaseScreen implements Screen {
}
@Override public void dispose() {
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/Ghostrifter-Deflector.mp3"));
uiStage.dispose();
mainStage.dispose();
}

View file

@ -48,6 +48,13 @@ public class GameScreen extends BaseScreen implements InputProcessor {
@Override
public void initialize() {
if (SagittariusGame.music.isPlaying()){
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/HMO-MercuryCity.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.play();
}
Gdx.input.setInputProcessor(this);
// arrows

View file

@ -18,6 +18,11 @@ public class SettingsScreen extends BaseScreen {
@Override
public void initialize() {
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/Metre - Concentric.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.play();
Gdx.input.setInputProcessor(uiStage);
// Table creation
@ -35,7 +40,8 @@ public class SettingsScreen extends BaseScreen {
// disable music checkbox
VisCheckBox disableMusic = new VisCheckBox("disable music");
disableMusic.setChecked(SagittariusGame.disableMusic);
// Change volume of the music
Spinner musicVolume= new Spinner("Music Volume:", new SimpleFloatSpinnerModel(SagittariusGame.music.getVolume(), 0f, 1.0f, 0.01f, 3));
@ -58,6 +64,14 @@ public class SettingsScreen extends BaseScreen {
SagittariusGame.soundsVolume = Float.parseFloat(musicVolume.getTextField().getText());
SagittariusGame.debugMode = debugModeBox.isChecked();
// Deactivate music or not
if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()){
SagittariusGame.music.stop();
}
else if (!disableMusic.isChecked() && ! SagittariusGame.music.isPlaying()){
SagittariusGame.music.play();
}
}
});

View file

@ -14,6 +14,23 @@ public class StartScreen extends BaseScreen {
@Override
public void initialize() {
// A welcome music is played
if (!SagittariusGame.disableMusic){
if ( SagittariusGame.music != null ){
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/Ghostrifter-Deflector.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.play();
}
else {
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/Ghostrifter-Deflector.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.play();
}
}
Gdx.input.setInputProcessor(uiStage);
// Table creation