簡體   English   中英

如何檢測停用后用戶何時再次運行WP7 XNA Application?

[英]How to detect when user has run WP7 XNA Application again while deactivated?

我有一個用XNA 4.0用C#編寫的Windows Phone 7游戲。

如果用戶執行以下操作,似乎可以避免Game.OnExiting方法:

  1. 通過Windows Phone OS中的Tile啟動游戲。
  2. 在游戲中,按Windows鍵離開游戲(導致一個呼叫Game.OnDeactivated但不Game.OnExiting )。
  3. 用戶通過Windows Phone OS中的圖塊再次啟動游戲。

我已經在WP7 App Lifecycle上學到了很多東西,但是在用戶連續兩次運行同一應用程序的情況下,卻找不到任何涉及的內容。

我有一些邏輯,只有在游戲關閉時才能調用它,並且不要錯過(例如上述情況),這一點也很重要。 我無法在OnDeactivated調用它,因為它會導致較差的用戶體驗。

這是有問題的代碼(位於我的Game類實現中):

protected override void OnExiting(object sender, EventArgs args)
{
    // This is what is getting missed!
    ForceSave();

    base.OnExiting(sender, args);
}

protected override void OnDeactivated(object sender, EventArgs args)
{
    base.OnDeactivated(sender, args);

    // I don't want to put ForceSave here because it will get called even if the user is not exiting the game.

    ...
}

protected override void OnActivated(object sender, EventArgs args)
{
    base.OnActivated(sender, args);

    ...
}

我認為您無法處理這種情況。
我不知道您的游戲是什么,但是最簡單的解決方案是在ForceSave結束時或在顯示另一個菜單之前調用ForceSave (我想這是一種保存方法),您只能在關閉菜單之前保存用戶的進度應用。 有時,游戲可能會無故崩潰,因此您必須避免這種情況。
簡而言之,您必須修改保存邏輯。

暫無
暫無

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

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