在SLXNA游戏[WP7]中制作加载页面

时间:2012-09-17 02:12:29

标签: c# windows-phone-7 xna

我正在开发一款适用于Windows Phone 7的游戏,我正在使用版本SLXNA(Silvelight + XNA)以及我所拥有的一切,问题是导航游戏页面需要花费很多时间(GamePage.xaml),我想制作一个“加载...”的页面,因为应用程序会保持原样,直到你看到游戏页面。

感谢您的回答。问候

1 个答案:

答案 0 :(得分:0)

您有几个选择:

这实际上取决于您希望加载发生在哪里。是游戏循环还是SL页面。 XNA Thread示例:

    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;
    }

例如,当用户按下屏幕时调用LoadResources方法

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

在游戏更新循环中

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

向用户展示一些东西是个好主意,例如

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

并在绘制循环中

        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);
        }
相关问题