TexturePacker XNA Content Pipeline Extension August 2, 2012
Posted by Jesse in : Game Development , 19 commentsTexturePacker is pretty awesome.
The next St. Louis game jam will take place this coming weekend, so I’ve been going through and cleaning up some of my base code. I haven’t seen an XNA content pipeline loader for TexturePacker atlases, so I decided to share mine.
ThirdPartyNinjas.XnaUtility.1.0.zip
There’s a simple test included, and it shows how to load a texture atlas, look up a texture in the atlas, and render that texture using a few different origin options.
If you have trimming turned on, using the origin options can make things easier. There are four main options:
- TextureRegion.OriginTopLeft. This will draw/rotate around the original (pre-trimmed) top-left.
- TextureRegion.OriginBottomRight. The original bottom-right.
- TextureRegion.Center. The original center.
- Calculate your own origin using Width and Height in TextureRegion.Bounds.
A few things to keep in mind:
- While the loader supports rotated sprites if you choose that option in TexturePacker, the XNA SpriteBatch doesn’t easily support UV rotations so you’ll need to do extra work.
- By default, TexturePacker will name the texture and atlas with the same base filename. (i.e. foo.png and foo.xml) You’ll need to change that, or change the asset name of one of them to prevent a filename collision at build time.
- The content importer supports either the JSON-Array or Generic XML export options in TexturePacker.
- I didn’t put any sort of license notice in the source, but feel free to use it however you want. Not attribution or acknowledgement required. (If you need a specific license or info, let me know.)
Yell if you have any problems.