10
\$\begingroup\$

I am wondering about in-game level design. My current situation revolves around Tiled - I have many different layers with different types of objects in them (for anyone who isn't familiar with Tiled, an object is nothing more than a coordinate with arbitrary properties assigned to it).

I am currently re-compiling the game every time I make a little change to my map file to see if everything is positioned properly. Is there a way for me to have my game automatically re-load the level if a map file change is detected? Does XNA even allow for this, or does the way the content pipeline work not allow for dynamic content in such a way? Any tips or suggestions are absolutely welcome.

\$\endgroup\$

2 Answers 2

8
\$\begingroup\$

I assume your map files are processed via the Content Pipeline, and then loaded at runtime with Content.Load. You have two options:

  • Save your maps as a XML file, via IntermediateSerializer.Serialize. Then, at runtime, you can read them with IntermediateSerializer.Deserialize to see the changes.
  • This is a tougher one: calling MSBuild at runtime to recompile your files into proper XNBs, and reloading them with the ContentManager. This sample does that.
\$\endgroup\$
1
  • \$\begingroup\$ Between the two, I'm sure I'll be able to sort something out. Thank you! \$\endgroup\$ Nov 21, 2010 at 1:01
2
\$\begingroup\$

You could also use Karvonite if you want to get this up and going really fast.

It's an agile persistence framework. I'm not sure if the new version will work on windows phone 7 or xbox.

You would create a persistence definition with their persistence editor (it's pretty easy, you just import the assembly and check the fields/properties on the classes/structures you want persisted) You initiate an ObjectSpace in code and add/remove/get objects from it. (these objects are persisted)

If you could create an abstraction so that the tile engine or whatever it is you call it doesn't care exactly how it gets the map, just that it gets the one it asked for. Then you can go back and use the XmlSerializer or the Intermediate one. (whichever you prefer) All you'd have to do to implement those other serializers is create another implementation of the abstraction (an interface or abstract class).

I think there is an example of how to build content at runtime on the XNA creator's club website. It might not be built with the latest framework though. That way you could keep your old code if you already use the content pipeline. Here's the link : Winform Series 2: Content Loading

\$\endgroup\$
3
  • \$\begingroup\$ I feel a bit silly asking this, but can you describe what you envision the workflow using this framework to be? It sounds really neat, but I am not sure how to approach it. \$\endgroup\$ Nov 23, 2010 at 23:54
  • 1
    \$\begingroup\$ Well, you define the serialization in their persistence editor. (it really easy, you just import your object assembly and check some boxes on the structures/classes and the fields/properties you want persisted) Once you've done that, you can just initialize an object space that will serialize/deserialize your objects. It's pretty neat and fast to get up and running. \$\endgroup\$ Nov 24, 2010 at 1:54
  • 1
    \$\begingroup\$ You can also look at this project on codeplex for a better example of how to build content outside of visual studio. (xnadevru.codeplex.com/…) \$\endgroup\$ Nov 24, 2010 at 2:07

You must log in to answer this question.

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