Wednesday, March 31, 2010

Reading and Writing XNA Game Data on the xbox

This is something that you think would be simple and straightforward but is actually a bit tricky. I found it tricky anyways, because I could not find adequate information on the subject from Microsoft's XNA and MSDN web sites. Surely, I could be missing something somewhere, but it wasn't apparent to me where I could find what I was looking for. After reading about a dozen or so blogs, forum posts, and MSDN pages, and struggling with my game for a few hours, I finally figured it out. This is what you need to know:


1. You need to use the XNA Storage API, which conveniently will automatically work with PC and xbox without having to code separately for each.


2. There are two separate file locations to work with, the TitleLocation and user-specific folders. The TitleLocation is read-only and stores all game related data that ships with the game. In my case, this is where my map and character data files are kept and read from. I simply place the files in the root folder of the project and add them to the project with properties set to "Copy if Newer" and "No Processing Required". The user-specific folders are read/write and this is where you can save/load games, store high-scores, etc. and it is per user (xbox or windows user).


3. When opening a stream to read data from your TitleLocation, be sure the access flag is set to read-only. It will crash if you open it any other way, even if you only plan to read from it.


I'm not going into all the details with code examples, because there's a lot to find on the internet already. I just wanted to point out some of the facts that I thought were missing from what I read in my research.

No comments:

Post a Comment