Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is it possible to pack all the little .xnb files into one big file? Given the level of abstraction of the XNA Framework I though this would come out of the box but I can't find any well integrated solution.

So far the best candidate is XnaZip but in addition to having to compile the resources in a post-build event, and a little trouble porting the game to XBOX I have to rename all the references to resources I have already implemented.

share|improve this question
    
Why do you have to rename references to your resources? After answering your question, I had a cursory glance at XnaZip; it seems like it should be a drop-in replacement -- aside from the missing System.IO.Compression namespace. –  Blair Holloway Feb 16 '11 at 12:58
    
In the readme of the XnaZip project it says: 'After that you can load your objects like this: Texture2D earth = content.Load<Texture2d>(ResourceId.Earth);' But now that you mention maybe I misinterpreted it and means 'you may' instead of 'you have to'. I will give it a try. –  Cristian Feb 16 '11 at 14:06
    
Why do you want to pack these files together? –  PrinceCharles Jan 5 '12 at 22:14
    
for easier distribution when you have tons of files and to hide internal resource names from plain sight –  Cristian Jan 10 '12 at 10:39
    
@PrinceCharles also keep in mind that copying one big file is much faster than copying many smaller ones (especially off of optical media). –  Jonathan Dickinson Feb 16 '12 at 15:25

1 Answer 1

up vote 4 down vote accepted

It's possible, but you either have to:

  • Find a library that does it for you, or
  • implement it yourself.

XNA lets you do the latter by deriving from the ContentManager class and replacing the OpenStream method; in fact, the documentation explicitly says:

protected virtual Stream OpenStream (string assetName)

Opens a stream for reading the specified asset. Derived classes can replace this to implement pack files or asset compression.

In the override version of OpenStream, one would simply return a compatible Stream that read the requested asset data from a pack file, rather than opening a FileStream from disk.

The tricky part is that you have to actually build the pack file yourself, incorporating the xnb files output via the content build pipeline. You could build a Content Pipeline Extension to do this, or find some other method, depending on what your goals are.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.