Xna Windows Phone 7保存游戏数据
我想知道如何将高分数据保存到windows phone上的独立存储中。我找了很多东西,但没有发现任何有用的东西。有人知道我怎么做吗 以下答案取自此MSDN条目: XNA Game Studio 4.0刷新不提供对可写文件的访问 Windows Phone上的存储。要访问此类存储,您需要使用 来自System.IO.IsolatedStorage命名空间的类 对于Windows Phone项目,Visual Studio会自动添加 包含System.IO.IsolatedStorage的程序集到项目。那里 无需向项目添加任何其他引用 将数据写入隔离存储器的示例:Xna Windows Phone 7保存游戏数据,xna,Xna,我想知道如何将高分数据保存到windows phone上的独立存储中。我找了很多东西,但没有发现任何有用的东西。有人知道我怎么做吗 以下答案取自此MSDN条目: XNA Game Studio 4.0刷新不提供对可写文件的访问 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);
}
谢谢,我怎么能在xna@Nahuell中找到退出事件。我现在无法在我的机器上尝试它,因为我的WP emulator有一些问题,但是onExiting方法是game类的一部分,您应该可以将它添加到Game1类中:如果不起作用,您也可以将代码添加到UnloadContent方法中,这是在退出游戏之前执行的。@user3453481更新,我可以在Windows游戏项目上执行此操作,我可以保证您可以将该方法添加到Game1类中。只需键入protectedoverride(空格),所有可以重写的方法就会显示给您。受保护的重写void OnExiting(对象发送方,EventArgs args){base.OnExiting(发送方,args);}它实际上不起作用。无法打开该文件。文件名必须是什么(格式)@不,格式应该是。(example.txt,example.xml)如果我没有错的话。你犯了什么错误?是否保存在其他目录中@用户3453481