首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xna Windows Phone 7保存游戏数据

Xna Windows Phone 7保存游戏数据
EN

Stack Overflow用户
提问于 2014-04-11 11:48:24
回答 1查看 139关注 0票数 0

我试图找出如何将高分数据保存到windows上的隔离存储中。我搜寻了无数的东西,却发现什么也没有用。有人知道我是怎么做到的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-12 10:53:26

以下答案取自此MSDN条目:

http://msdn.microsoft.com/en-us/library/ff604992.aspx

XNAGameStudio4.0Refresh不提供对Windows上可写存储的访问。要访问这样的存储,您需要使用System.IO.IsolatedStorage命名空间中的类。 对于Windows项目,Visual会自动将包含System.IO.IsolatedStorage的程序集添加到项目中。不需要向项目添加任何其他引用。

将数据写入隔离存储的示例:

代码语言:javascript
复制
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);
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23011753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档