XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Custom classes within custom classes in the content pipeline

Last post 6/11/2008 3:42 AM by spookyjon. 2 replies.
  • 6/7/2008 9:23 PM

    Custom classes within custom classes in the content pipeline

    I'm back with another content pipeline question, and hopefully it isn't too unbearably stupid.

    I've working on a 2D side-Scrolling Mario-esque game (it's my first XNA project, starting off with something relatively easy) and I have a basic, working cusom content reader/writer for my Block objects, basically background tiles that the player can walk on and collide with.  It's all working where I can load the xnb file into a List<Block> with no problems whatsoever.

    Now that I've implemented enemies (a class called Species), along with some other basic level information, I have a Level class that consists of the following:
    a List<Block>
    a List<Species> (the enemies)
    a handful of Vector2s, ints, strings, et cetera

    I don't think I'll have a problem implementing the Species importer, because it should behave more or less the same way as the Block importer.  What my concern is, though, is how this works alongside the Block importer, and how it works in the greater context of a Level importer.

    Do each of these need to be in a separate Content Pipeline project within the solution?  How do they interact with one another?  Are there any existing examples or tutorials for these "nested" pipelines?  The sample project from the XNA site made it seem like it wasn't much of a leap to do this, but I'm having some difficulties figuring out how best to move forward.  Thanks!

    (I've got the whole project zipped here, if that's in any way helpful--if you download it and want to point out some other aspects of my retardation, please feel free to do so.  I could use the help.)
  • 6/8/2008 4:38 AM In reply to

    Re: Custom classes within custom classes in the content pipeline

    The first thing you need to decide is how you want to create these level files.

    I'm guessing your importer reads the Block data from some kind of text format, maybe XML?

    If so, do you want your level files to be a single larger XML file that includes all the block data and species data along with other stuff, or do you want each block to stay in a separate file, and just refer to the name of that file from your main level file? If the former, you can use the same approach you currently do to read in the XML, and just apply it to a more complex data type. If the latter, you can set up the level importer to read in the string filenames for each sub object in the level, and then make a processor that calls context.BuildAndLoadAsset for each of these sub elements, which will call in to a different importer to load that file and return you the object data.

    Once you have your data all ready to go at the end of the processor, the only remaining part is the ContentTypeWriter that saves it into .xnb format. You can either just make one big ContentTypeWriter that manually saves out everything in one go, or you can make smaller ContentTypeWriter implementations that handle Block, Species, etc, and then have your main Level writer call writer.WriteObject to save out each sub object. If you call WriteObject on a type of your own, that will call through into the ContentTypeWriter implementation for that particular type. Then apply the same pattern in your ContentTypeReader to pull the data into your game.

    You don't need a separate content project for each type: it's fine to have many importers, processors, ContentTypeWriters, etc, all in the same project.

     

    XNA Framework Developer - blog - homepage
  • 6/11/2008 3:42 AM In reply to

    Re: Custom classes within custom classes in the content pipeline

    Thanks a lot!  You've been a great help.
Page 1 of 1 (3 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG