views:

410

answers:

2

I am planning on building a 2D game library for XNA, and one of the components I want to include is a simple text drawer for debug purposes. Now, to draw text with SpriteBatch you need a .spritefont file, which is an xml format file, and these seem to need to compile into a separate folder. I would prefer not to have to copy that around with the dll, so here is my question: can i build some sort of text renderer for XNA that A: does not require me to carry around external files with the dll (if you can embed the sprite font into a dll then that works) and B: does not force me to rewrite a fair amount of underlying (is it managed directx? a different part of xna?) code that makes the SpriteBatch.DrawString code work.

+2  A: 

Could you not just require that a SpriteFont be passed into your library, so that whoever is using the library has to supply that component? That would seem to be the best solution, since then they could use whatever font they wanted. Or you could write in a component that generates the spritefont xml file based on a given font name, because it's not all that complicated of a file. Disregard. I forgot that XNA compiles its resources.

Annath
The first possibility: yeah that could work and I suppose I'll have to do that if nothing else works, but I would really prefer not to do that. After all, you could theoretically pass in a Wingdings font and get something totally unreadable! Second possibility: that could work except all xna code that i know of works with compiled versions of files (turns it into xnb files which are binary representations), and getting dynamic comiplation out of XNA is another jig altogether.
RCIX
I suppose it would be up to the user of the library not to pass in wingdings. :P And yeah, I forgot that it compiled them into xnb files.
Annath
All right i'll just ask for a spritefont. Thanks for the help!
RCIX
A: 

You can precompile the project and then grab the xnb file for the spritefont. Then add the file to the project Content folder as a content file. It should then be deployed together with the library. However u will need to build a separate xnb file for each platform you wish to support (xbox360, windows, zune) and deploy the correct file.

Or why don't u just create a XNA Content Library project?

anonymous