I am doing 2D game using XNA framework 4.0. I'd like the game to have multiple levels. Where do I store the levels and how do I implement a scoring system for the game? Can I use XML for storing data for that levels and scores? Finally, is there any code samples for a multiple level game in Windows phone 7 using XNA 4.0?


See the platformer kit on the app hub. Includes Xbox, PC, and WP7.


It has examples of what you are asking (including XML levels).


Well, you can store games in the content folder (make sure to set them to compile:none in the item properties) and then load them using

[Microsoft.Xna.Framework.Storage.TitleLocation + Content.RootDirectory + file_name]

using something like StreamReader or XML (it also does not have to be in the content folder but just the game root directory). To load them, either hard code their names into the game or name the files like 1.level, 2.level, etc.

  • \$\begingroup\$ I don't think this is possible anymore in XNA4 on WP7. In previous versions you would use the StorageContainer.Path property along with normal System.IO to perform your file operations. In XNA Game Studio 4.0, we’ve moved in a direction more aligned with the IsolatedStorage APIs where StorageContainer now exposes many file operations as methods such as CreateFile, GetDirectories, and FileExists. blogs.msdn.com/b/nicgrave/archive/2010/07/23/… \$\endgroup\$ – Roy T. May 23 '12 at 16:45
  • \$\begingroup\$ I forget, but in any case you can just write a generic content reader \$\endgroup\$ – CobaltHex May 24 '12 at 1:16

You can store arbitrary XML files in the XNA asset manager but remember to set the compiling off for those files (so the remain as plain text and don't get saved as binary files). You can see an example in my open source game Urban Race. It's 3D but the concept still applies, I read XML for the levels at runtime, just what you want.

  • \$\begingroup\$ -1 this won't work in WP7, you actually do have to compile the XML files and then use the XML content importer to read them. \$\endgroup\$ – Roy T. May 23 '12 at 8:16
  • \$\begingroup\$ Didn't know that. \$\endgroup\$ – David Saltares May 23 '12 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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