jump to navigation

TexturePacker XNA Content Pipeline Extension August 2, 2012

Posted by Jesse in : Game Development , 20 comments

TexturePacker 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:

  1. TextureRegion.OriginTopLeft. This will draw/rotate around the original (pre-trimmed) top-left.
  2. TextureRegion.OriginBottomRight. The original bottom-right.
  3. TextureRegion.Center. The original center.
  4. Calculate your own origin using Width and Height in TextureRegion.Bounds.

A few things to keep in mind:

  1. 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.
  2. 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.
  3. The content importer supports either the JSON-Array or Generic XML export options in TexturePacker.
  4. 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.