Game Development Reference
In-Depth Information
102 SetTransform();
103 }
104 //-----------------------------------------------
105 public void SaveBinary(string FileName = "GameData.sav")
106 {
107 //Get transform data
108 GetTransform();
109
110 BinaryFormatter bf = new BinaryFormatter();
111 FileStream Stream = File.Create(FileName);
112 bf.Serialize(Stream, MyData);
113 Stream.Close();
114 }
115 //-----------------------------------------------
116 public void LoadBinary(string FileName = "GameData.sav")
117 {
118 //If file doesn't exist, then exit
119 if(!File.Exists(FileName)) return;
120
121 BinaryFormatter bf = new BinaryFormatter();
122 FileStream Stream = File.Open(FileName, FileMode.Open);
123 MyData = bf.Deserialize(Stream) as MySaveData;
124 Stream.Close();
125
126 //Set transform - load back from a file
127 SetTransform();
128 }
129 //-----------------------------------------------
130 }
131 //-----------------------------------------------
A full example of loading and saving game data can be found in the
topic's companion iles in the Chapter10/XML_and_Binary folder.
 
Search WWH ::




Custom Search