2

currently I' using XNA 4.0 Game Studio and the Window Game Statement Management template which is provide by Visual Studio 2010 to develop a game. Is there any suggestion about how to save and load the state of a game? Previously I've develop a window phone game and the data is stored inside IsolatedStorage. Is there any similarity for the Window Game?

         using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                using(IsolatedStorageFileStream stream = file.OpenFile("class123.xml",FileMode.Create))
                {
                    XmlWriterSettings setting = new XmlWriterSettings();
                    setting.Indent = true;
                    using(XmlWriter writer = XmlWriter.Create(stream,setting))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(Student));
                        serializer.Serialize(stream,new Student(){Name = "AhLim"});
                    }

                    using (XmlReader reader = XmlReader.Create(stream))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(Student));
                        studentA = (Student)serializer.Deserialize(reader);
                    }
                }
            }

Here's the code i recently used in Window Game Applicaiton. However, when i reach to Deserialize part, it show InvalidOperationException was unhandled and error on XML document (0,0) . May i know where's the problem?

1
  • Windows (XP/Vista/7) does have an Isolated Storage Commented Dec 27, 2012 at 10:09

2 Answers 2

3

The code used in a Windows Phone game should work fine on PC. Data would be stored in C:\Users\\Documents\SavedGames

1

Try

 serializer.Serialize(writer, new Student() { Name = "AhLim" });

instead of

 serializer.Serialize(stream, new Student() { Name = "AhLim" });

Looks like IsolatedStorageFileStream is using the wrong encoding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.