簡體   English   中英

從xaml頁面返回monogame游戲頁面。 (Windows Phone 8.1運行時)

[英]Getting back to monogame game page from xaml page. (Windows Phone 8.1 runtime)

我為游戲創建了一個單獨的xaml頁面,其中將顯示全局提交的高分。 我正在為游戲使用monogame庫,並且在瀏覽游戲頁面和新的xaml頁面時會遇到一些問題。

我已經成功解決了如何使用以下代碼將用戶導航到顯示高分的xaml頁面:

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

我所期望的問題是,當我想將用戶導航回到單機游戲頁面時,那里沒有必須繪制的所有圖形...我只是黑屏,我什么也不能做。 我用來將用戶從xaml頁面導航回monogame游戲頁面的代碼與上面的代碼幾乎相同:

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

沒有繪制圖形可能是什么問題?

謝謝。

我終於找到了解決我問題的方法。 @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頁面,然后返回。 但是當您再次執行此操作時,游戲將退出...而且我現在不知道為什么...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM