Sound lässt sich ein und aus schalten, settings pref erstellst
This commit is contained in:
parent
30bd801355
commit
db4c1feb4e
@ -2,6 +2,7 @@ package de.samdev.colorrunner.game.world;
|
||||
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
@ -17,6 +18,7 @@ import de.samdev.colorrunner.screens.gameScreen.GameScreen;
|
||||
import de.samdev.colorrunner.screens.menu.MainMenu;
|
||||
|
||||
public class CRGameWorld implements GameInputListener {
|
||||
private Preferences prefs = Gdx.app.getPreferences("settings");
|
||||
public PlayerEntity player;
|
||||
public List<CRGameEntity> entities;
|
||||
|
||||
@ -26,15 +28,17 @@ public class CRGameWorld implements GameInputListener {
|
||||
public MapProvider mapprovider;
|
||||
private Music music;
|
||||
public int scoreMeter = 0;
|
||||
|
||||
|
||||
|
||||
public CRGameWorld(MapProvider prov) {
|
||||
mapprovider = prov;
|
||||
|
||||
|
||||
music = CRGame.manager.get("sound/mainsound.mp3", Music.class);
|
||||
music.setLooping(true);
|
||||
music.play();
|
||||
|
||||
if(prefs.getBoolean("sound", true))
|
||||
music.play();
|
||||
else
|
||||
music.stop();
|
||||
|
||||
reinitialize();
|
||||
}
|
||||
|
@ -30,10 +30,6 @@ public class GameScreen implements Screen {
|
||||
renderer = new CRGameRenderer(world, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // initialize renderer
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
input = new CRGameInputProcessor(world);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.samdev.colorrunner.screens.menu;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
@ -28,6 +29,7 @@ import de.samdev.colorrunner.screens.gameScreen.GameScreen;
|
||||
|
||||
public class MainMenu implements Screen {
|
||||
|
||||
private Preferences prefs = Gdx.app.getPreferences("settings");
|
||||
private Stage stage = new Stage();
|
||||
private Table table = new Table();
|
||||
|
||||
@ -72,14 +74,16 @@ button3.addListener(new InputListener(){
|
||||
|
||||
private Label title = new Label("Color Runner", skin);
|
||||
|
||||
private Music music;
|
||||
public Music music;
|
||||
|
||||
public MainMenu() {
|
||||
music = CRGame.manager.get("sound/menusound.mp3", Music.class);
|
||||
music.setLooping(true);
|
||||
music.play();
|
||||
|
||||
music = CRGame.manager.get("sound/menusound.mp3", Music.class);
|
||||
music.setLooping(true);
|
||||
|
||||
if(prefs.getBoolean("sound", true))
|
||||
music.play();
|
||||
else
|
||||
music.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,7 +133,7 @@ button3.addListener(new InputListener(){
|
||||
buttonOption.addListener(new ClickListener(){
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
CRGame.Inst().setScreen(new OptionMenuScreen());
|
||||
CRGame.Inst().setScreen(new OptionMenuScreen(music));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2,7 +2,9 @@ package de.samdev.colorrunner.screens.menu;
|
||||
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
@ -20,6 +22,7 @@ import de.samdev.colorrunner.screens.gameScreen.GameScreen;
|
||||
|
||||
public class OptionMenuScreen implements Screen{
|
||||
|
||||
private Preferences prefs = Gdx.app.getPreferences("settings");
|
||||
private Stage stage = new Stage();
|
||||
private Table table = new Table();
|
||||
private Texture background = new Texture("images/background2.jpg");
|
||||
@ -27,9 +30,10 @@ public class OptionMenuScreen implements Screen{
|
||||
|
||||
private Skin skin = new Skin(Gdx.files.internal("skins/menuSkin.json"),
|
||||
new TextureAtlas(Gdx.files.internal("skins/menuSkin.pack")));
|
||||
private Music music;
|
||||
|
||||
public OptionMenuScreen() {
|
||||
//cam.setToOrtho(false, (float)Gdx.graphics.getWidth() / 2, (float)Gdx.graphics.getHeight() / 2);
|
||||
public OptionMenuScreen(Music music) {
|
||||
this.music = music;
|
||||
}
|
||||
|
||||
private Label title = new Label("Option", skin);
|
||||
@ -60,14 +64,27 @@ public class OptionMenuScreen implements Screen{
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
|
||||
TextButton buttonSound = new TextButton("Sound On/Off", skin);
|
||||
TextButton buttonSound;
|
||||
if(prefs.getBoolean("sound", true))
|
||||
buttonSound = new TextButton("Sound On", skin);
|
||||
else
|
||||
buttonSound = new TextButton("Sound Off", skin);
|
||||
|
||||
TextButton buttonBack = new TextButton("Back", skin);
|
||||
|
||||
buttonSound.addListener(new ClickListener(){
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y){
|
||||
|
||||
if(prefs.getBoolean("sound", true)) {
|
||||
prefs.putBoolean("sound", false);
|
||||
music.stop();
|
||||
}
|
||||
else {
|
||||
prefs.putBoolean("sound", true);
|
||||
music.play();
|
||||
|
||||
}
|
||||
((Game)Gdx.app.getApplicationListener()).setScreen(new OptionMenuScreen(music));
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user