3
\$\begingroup\$

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?

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

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

http://create.msdn.com/en-US/education/catalog/sample/platformer

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

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\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.
    Commented May 23, 2012 at 16:45
  • \$\begingroup\$ I forget, but in any case you can just write a generic content reader \$\endgroup\$
    – CobaltHex
    Commented May 24, 2012 at 1:16
-1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\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.
    Commented May 23, 2012 at 8:16
  • \$\begingroup\$ Didn't know that. \$\endgroup\$ Commented May 23, 2012 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .