Packing Text Files in XNA 3.0

Started by
3 comments, last by Wrathnut 15 years, 3 months ago
I have a quick question about packing files into an XNA 3.0 build. I have a bunch of text files that I use for level data information and was wondering if there was a way to pack them into the build process. Kind of like the way that image and sound data are packed into the build. Currently I have sounds packed up so that when I build the project the audio is put into the content\audio directory. Is there a way to add text files to the build so that when the project is built it goes into a folder like content\levels? Thanks in advance.
Advertisement
Well the easy thing to do is to just add them to your Content project, set them to NOT compile, and then set them to be copied to the output folder on build. This will simply copy the file to Content\Levels (or whatever you named the folder in your Content project).

If you wanted to get fancier, you could make a very simply Content Importer and Processor that simply loads the text file as a string and saves it as a .xnb file. This would give you content compression, and would also let you use the ContentManager to load the level data.
Thanks MJP.

I think I tried that last night but when I tried to compile I got an error that said something about it needing an appropriate content importer. so I tried messing around with that but didn't get anywhere. I will try messing around with it again tonight. If it is that easy I should be able to figure it out. I will try to copy down the exact error I am getting when I compile.

Thanks again
Yeah you need to set the Content not to compile the file by setting the "Build Action" property to "None" (sorry I couldn't remember the property name earlier when I was at work). Then set the "Copy To Output Directory" property to "Always".
Yeah thanks, that did work. I did exactly that when got hope and it worked like a charm!

This topic is closed to new replies.

Advertisement