简体   繁体   English

停止开始音乐-Libgdx Java

[英]stop start music - Libgdx Java

In my game I have a music class that organizes and plays all of the music: 在我的游戏中,我有一个音乐课来组织和播放所有音乐:

public class MusicPlayer extends Game{
(..)
    public static void MainBackgroundMusic(){

    if(backgroundMusicPlaying != true){
        backgroundMusic.play();
        backgroundMusic.setVolume(0.1f);
        backgroundMusic.setLooping(true);
        backgroundMusicPlaying = true;
        }

    }

    public static void BackgroundStop(){
    if(backgroundMusicPlaying = true){
        backgroundMusic.stop();
        }
    }

I want to be able to stop the music from playing, during levels then restart it again. 我希望能够在播放音乐时停止播放音乐,然后重新启动它。 But when i try and restart it it doesn't play again. 但是,当我尝试重新启动它时,它不会再播放。

I call the music to play at the start of the game: 我将音乐称为在游戏开始时播放:

public OptionScreen(final Game1 gam){
    (..)
    MusicPlayer.MainBackgroundMusic();
    (..)
    }
    public void render(float delta) {
       (..)
}

Then during the start of the level I call the stop: 然后在关卡开始时我叫停:

public InsaneLevels(Game1 gam) {
        (..)
        MusicPlayer.BackgroundStop();
        (..)
    }
    public void render(float delta) {
        (..)
}

And when i go back to the start it doesn't replay. 当我重新开始时,它不会重播。

Set the backgroundMusicPlaying to false inside of your stop method. 在stop方法内部将backgroundMusicPlaying设置为false。 Guess you forgot this. 猜猜你忘了这个。 Also you should have this: 另外,你应该有这个:

backgroundMusicPlaying == true

Instead of: 代替:

backgroundMusicPlaying = true

    public static void BackgroundStop() {
        if (backgroundMusicPlaying == true) {
            backgroundMusic.stop();
            backgroundMusicPlaying = false;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM