Addendum Content processors

In the previous article I wrote about the Content Reader in contentprojects. I stated that the content reader can happily live inside the content project. This means that the “filetype” project also hold all classes to process the content. Seems I have to expand on that…

If the project is fairly simple, such as the flatshaded model, that is acceptable. However, I was making some more complex projects.
For example, the Darkfunction Editor uses a few files to store animations: the .png file that holds the images, the .sprite file that holds the definition of sprites inside the image and finally the .anim file that constructs the animations out of those components. In the final game project, I wanted to simply load an animated content file that combines these things automatically for me.

So I made an AnimatedSprite that held all the relevant information and a AnimationController that could play animations from the AnimatedSprite data. So far things went great.

When I started creating the ContentProcessor, I found that the structure to write the .xnb file was quite different than the structure I needed to actually use the data. For example; the textures that I needed in the AnimatedSprite data are handled differently in a content project (more on that later). In fact, the content processor was much simpeler than the actual object.

So by separating the content project from the AnimatedSprite project, things were much simpeler.

Keep in mind that in the ContentWriter function you have to point to the correct ContentReader:

Textures in Content Processors

Sometimes you might want to include textures in a content project. In the example above, the .anim file is added to the Content. Inside the .anim file a .sprite file is referenced. The .sprite file in turn references a texture.  It would be awesome if the game project could simply load the anim content and the rest is magically loaded as well.

This is the trick (in the ContentProcessor code):

In the above code a texture texturefilename is build and saved as texturetargetname.  By storing the targetname in your contentfile, you can simply read the texture in your ContentReader:

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *