【发布时间】:2014-04-12 18:53:26
【问题描述】:
我正在尝试找出如何将高分数据保存到 Windows Phone 上的隔离存储中。我搜索了很多东西,但没有发现任何工作。有谁知道我该怎么做?
【问题讨论】:
标签: xna
我正在尝试找出如何将高分数据保存到 Windows Phone 上的隔离存储中。我搜索了很多东西,但没有发现任何工作。有谁知道我该怎么做?
【问题讨论】:
标签: xna
以下答案取自此 MSDN 条目:
http://msdn.microsoft.com/en-us/library/ff604992.aspx
XNA Game Studio 4.0 Refresh 不提供对可写的访问 Windows Phone 上的存储。要访问此类存储,您需要使用 System.IO.IsolatedStorage 命名空间中的类。
对于 Windows Phone 项目,Visual Studio 会自动添加 包含 System.IO.IsolatedStorage 的程序集到您的项目中。那里 无需为您的项目添加任何额外的引用。
将数据写入独立存储的示例:
protected override void OnExiting(object sender, System.EventArgs args)
{
// Save the game state (in this case, the high score).
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
// open isolated storage, and write the savefile.
IsolatedStorageFileStream fs = null;
using (fs = savegameStorage.CreateFile(SAVEFILENAME))
{
if (fs != null)
{
// just overwrite the existing info for this example.
byte[] bytes = System.BitConverter.GetBytes(highScore);
fs.Write(bytes, 0, bytes.Length);
}
}
base.OnExiting(sender, args);
}
【讨论】: