0

我正在为 Windows Phone 7 开发游戏,我正在使用版本 SLXNA (Silvelight + XNA) 和我拥有的一切,问题是导航游戏页面 (GamePage.xaml) 需要很多时间,我想制作一个显示“正在加载..”的页面,因为应用程序会一直停留在原处,直到您看到游戏页面。

感谢您的回答。问候

4

1 回答 1

0

You have a few options:

It really depends where do you want the loading to happen. Is it a game loop or a SL page. XNA Thread example:

    private Thread thread;
    private bool isLoading;
    private void LoadResources()
    {
        // Start loading the resources in an additional thread
        thread = new Thread(new ThreadStart(gameplayScreen.LoadAssets));

        thread.Start();
        isLoading = true;
    }

For example LoadResources method is called when user press tap the screen

        if (!isLoading)
        {
            if (input.Gestures.Count > 0)
            {
                if (input.Gestures[0].GestureType == GestureType.Tap)
                {
                    LoadResources();
                }
            }
        }

In the game update loop

        if (null != thread)
        {
            // If additional thread finished loading and the screen is not
            // exiting
            if (thread.ThreadState == ThreadState.Stopped && !IsExiting)
            {
               //start the level
            }
        }

It's good idea to show something to the user e.g.

        private static readonly string loadingText = "Loading...";

and in the draw loop

        if (isLoading)
        {
            Vector2 size = smallFont.MeasureString(loadingText);
            Vector2 messagePosition = new Vector2(
                (ScreenManager.GraphicsDevice.Viewport.Width - size.X) / 2,
                (ScreenManager.GraphicsDevice.Viewport.Height - size.Y) / 2);
            spriteBatch.DrawStringBlackAndWhite(smallFont, loadingText, messagePosition);
        }
于 2012-09-17T02:42:25.463 回答