hi
i making a game which i want to be able to save out the important detail and be able to read it again at a later date (like .SAV files for games). but i don't know where to start.
I'm using XnA 3 with VisualStudio 2008. this is being designed for pc and xbox360 so i need to know how both will work.
any toutarials ya know of would be great cause i can't find any (not good with internet) i dont know much on saving and loading so i'm learning this bi from scrath
thanks for any help
Since I am not entirely sure what you want to save and what format you want to use I suggest you look through these C# File Stream Samples. There's examples for text files, binary files, and a bunch of other save methods.
The thing is i don't know anything about it so i don't know what i want. this is why i need help to learn it and then use it.
I need to find a way or a few of saving out all the data i require I.E , will include, player: level, items, weapons, powers etc,. world changes, list<T> of differening lengh and any so on. hope that makes it easy.
i'll check out the site and see what i can find thanks
okay i've looked at a bit and found that i think the text saving is to constricve.
but i think i can do want i want using xml.
looking at XNA Essentials as an example could work in my idea.
I just got a few questions that i want to ask,
1) xml looks like you can load and save a serizable strut, would it be possible to make a seizale class
2) it dosen't mention any limits so can you store higher acrhy of lists i.e. list of players party, with list of items on each, so on ans so forth. (save an entire class)
3) and i think it unlikely but could ya save in sections in the xml, or combine xml files into another type so ya could do something a section at change so player destory city, can ya just save that part or do you have to save entire game.
i've one some reseach and i've come up with this
I've tested it a Vector2, and it seems to workCode:using System; using System.IO; using System.Collections.Generic; using Microsoft.Xna.Framework.Storage; using System.Text; using System.Xml.Serialization; //Kavery //K_SaveManager V1.0 //28-01-2010 namespace KaveryFramework2D { /// <summary> /// a Class that can save any class data Class /// will have an auto save. function /// may have large file size but this was all i could understand /// </summary> /// <typeparam name="ClassToSave"></typeparam> [Serializable] class K_SaveManager<ClassToSave> //where ClassToSave : new() { //require for serialization public K_SaveManager() { } public void Save(ClassToSave data, string fileName) { // Get the path of the save game string fullpath = Path.Combine(StorageContainer.TitleLocation, fileName); // Open the file, creating it if necessary FileStream stream = File.Open(fullpath, FileMode.OpenOrCreate); try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer(typeof(ClassToSave)); serializer.Serialize(stream, data); } finally { // Close the file stream.Close(); } } public void AutoSave(ClassToSave data) { Save(data, "AutoSave"); } public ClassToSave AutoLoad() { return Load("AutoSave"); } /// <summary> /// will load default obhect if there n load /// </summary> /// <param name="fileName"></param> /// <returns></returns> public ClassToSave Load(string fileName) { ClassToSave data; // Get the path of the save game string fullpath = Path.Combine(StorageContainer.TitleLocation, fileName); FileStream stream; // Open the file se to null if no there try { stream = File.Open(fullpath, FileMode.Open, FileAccess.Read); } catch { //stream = File.Open(fullpath, FileMode.OpenOrCreate, FileAccess.Read); data = default(ClassToSave); return data; } try { // Read the data from the file XmlSerializer serializer = new XmlSerializer(typeof(ClassToSave)); data = (ClassToSave)serializer.Deserialize(stream); } finally { // Close the file stream.Close(); } return (data); } } }
if anyone can notice a problem or a knows better way i'm happy to hear ya ideas.
oh yeah and thankz for the link it got me startedand give me a chance to improve my personal framework.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks