【问题标题】:Getting back to monogame game page from xaml page. (Windows Phone 8.1 runtime)从 xaml 页面返回单人游戏页面。 (Windows Phone 8.1 运行时)
【发布时间】:2015-03-12 21:48:08
【问题描述】:

我为我的游戏创建了一个单独的 xaml 页面,我将在其中显示全球提交的高分。我正在为我的游戏使用 monogame 库,我预计在浏览游戏页面和新的 xaml 页面时会出现一些问题。

我已经成功地解决了如何使用以下代码将用户导航到显示高分的 xaml 页面:

var frame = new Frame();
frame.Navigate(typeof(SubmitScoreDialog)); //SubmitScoreDialog the xaml page
Window.Current.Content = frame;
Window.Current.Activate();

我期待的问题是,当我想将用户导航回单人游戏页面时,所有必须绘制的图形都不存在......我只是黑屏,我什么也做不了.我用来将用户从 xaml 页面导航回单人游戏页面的代码与上面的代码几乎相同:

var frame = new Frame();
frame.Navigate(typeof(GamePage));
Window.Current.Content = frame;
Window.Current.Activate();

我的图形没有绘制可能是什么问题...?

谢谢。

【问题讨论】:

  • 也许我完全错过了这里的问题,但是......为什么不直接使用 Windows Phone 提供的标准页面导航?
  • 标准页面导航是什么?我 GamePage.xaml 是标准游戏页面,SubmitScoreDialog 是第二个 xaml 页面,我在导航回游戏页面时遇到问题。
  • 问题不是在页面中导航。我知道该怎么做。问题是我从另一个 xaml 页面返回到 monogame 游戏页面后,我的游戏没有恢复(什么都没有绘制,黑页)....
  • 哦,等一下,您正在使用最新的稳定单人游戏版本,对吧?我的意思是您从他们的网站下载并安装的那个。

标签: c# windows-phone-8 monogame


【解决方案1】:

我终于找到了解决问题的方法。 @Bjarke Sogaard 如果您也想解决您的问题。使用以下代码更改 OnLaunched 事件中的 App.xaml.cs:

//Declare this variables up in the app.xaml.cs class
public GamePage GamePage;

//In OnLaunched:
var app = App.Current as App;

// Create a main GamePage
if (app.GamePage == null) app.GamePage = new GamePage(string.Empty);
// Place the GamePage in the current Window
Window.Current.Content = app.GamePage;
Window.Current.Activate();

然后,输入这段代码,从游戏页面导航到 xaml 页面:

var frame = new Frame();

frame.Navigate(typeof(SubmitScoreDialog));

Window.Current.Content = frame;

然后导航回游戏页面(在我的例子中是 SubmitScoreDialog.xaml.cs):

var app = App.Current as App;

// Create a main GamePage

if (app.GamePage == null) app.GamePage = new GamePage(string.Empty);
Game1.statics.graphics.SupportedOrientations = Microsoft.Xna.Framework.DisplayOrientation.LandscapeRight | Microsoft.Xna.Framework.DisplayOrientation.LandscapeLeft;
// Place the GamePage in the current Window
Window.Current.Content = app.GamePage;

我不得不提一下,这不会 100% 解决问题。您可以从游戏页面导航到 xaml 页面,然后返回。但是当你再次这样做时,游戏退出了......我现在不知道为什么......

【讨论】:

    猜你喜欢
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多