简体   繁体   中英

Monogame for WP8 - Loading a pause screen when deactivating

I am trying to hande the situation where the user presses the start button or search button and sets the app to its dormant state. I basically want it to load a pause screen so that when the user returns to the application, the pause screen is displayed.

I am running into difficulty when I try to create the new screen within the deactivated method - I cannot load any content as things like the content manager have already been disabled.

Is there any way around this? Ie can I load new content in the deactivated method?

here is my code thus far:

    void GameDeactivated(object sender, DeactivatedEventArgs e)
    {
        // Mute the game.
        //MediaPlayer.IsMuted = true;
        //AudioManager.IsMuted = true;

        GameScreen[] screens = mScreenManager.GetScreens();

        if(screens[screens.Length - 1] is GameplayScreen)
        {
            Debug.WriteLine("I am here and the last screen is a gameplay one");

            GameplayScreen gs = (GameplayScreen) screens[screens.Length - 1];

            Debug.WriteLine("here and " + gs.Level.LevelData.Index);

            //AudioManager.PauseSong();

            // This is the error line as when it tries to load the new screen it gets null reference exceptions.
            //mScreenManager.AddScreen(new PauseScreen(gs.Level.LevelData), null);

        }


        base.OnDeactivated(sender, e);


    }

I encourage you to implement some pre-content loading so it will solve your OnDeactivate issues. Loading "on demand" can make your game "laggy" in some cases - ie new monster is rendered first time - content is loading -> calls to content file on disk -> low fps for a ~sec. You can also add some boolean like wasGameDeactivated and load pause state in OnGameActivated .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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