Skip to content

Generic XML exporter

How it works

Packrat writes the TexturePacker-compatible generic XML format and one image file per atlas page. A single-page export is atlas.xml plus its image; a multipack uses numbered pairs such as atlas_1.xml and its image. The XML describes the page size and each frame's packed rectangle. Trimmed frames also include their original size and offset.

API

The XML has this shape. XML attribute values are strings; integer shows an attribute whose text contains a decimal integer. The trim and rotation attributes are optional:

xml
<?xml version="1.0" encoding="UTF-8"?>
<TextureAtlas imagePath="string" width="integer" height="integer">
  <sprite
    n="string"
    x="integer" y="integer" w="integer" h="integer"
    r="y"
    oX="integer" oY="integer" oW="integer" oH="integer" />
</TextureAtlas>
  • imagePath, width, and height describe the page image.
  • n is the exported frame name. Indexed source frames use zero-based names such as run_side_0000.
  • x, y, w, and h are the packed image rectangle.
  • r="y" marks a rectangle packed rotated 90 degrees; the attribute is absent for unrotated frames.
  • oX, oY, oW, and oH are the top-left trim offset and original size. They are absent when the frame was not trimmed.

Integrate

Parse the XML, load the image named by imagePath, and sample each sprite's x, y, w, and h rectangle. If oX/oY/oW/oH are present, place the sampled pixels inside the original frame using those values:

text
atlas = parse_xml("atlas.xml")
image = load_image(atlas.imagePath)
sprite = atlas.sprite("player_0000")
draw_image(image, sprite.x, sprite.y, sprite.w, sprite.h,
           sprite.oX, sprite.oY, sprite.oW, sprite.oH)

The parser and drawing calls are placeholders for your runtime. Rotate the sample when r="y" is present. If the oX/oY/oW/oH attributes are absent, use zero offsets and the packed size as the original size.

Packrat documentation