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?
The code used in a Windows Phone game should work fine on PC. Data would be stored in C:\\Users\\\\Documents\\SavedGames
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.