Using xml files

A .xml file is like a map that tells the game where to find a certain texture in a .tex file.


The file always starts with an <Atlas>  container, followed by <Texture filename = "foo.tex" /> <Elements>  and then the individual images and their coordinates, like so:  <Element name="bar.tex" u1="0.648" u2="0.7864" v1="0.243" v2="0.64" />


u1 and u2 are the horizontal coordinates where your tex file starts and ends divided by the total width of the file (that’s decimal percent, if you will). Similarly, the v1 and v2 are vertical coordinates divided by the height of the file.

Let’s say you have a 1024×1024 tex file. In it, you have different images. The pixel coordinates of image_1 are (x250, y100) to (x300, y200). That would make; u1 = 250/1024 (or 0.24414), u2 = 300/1024 (or 0.29297), v1 = 100/1024 (or 0.09766), and v2 = 200/1024 (or 0.19531).

The coordinates for image_1 would be written as  u1 = "0.24414" u2 = "0.29297" v1 = "0.09766" v2 = "0.19531".

Tips and Suggestions

You may need to invert the y-axis depending on the software you use to check your pixel coordinates. Some image softwares count from the bottom left corner and others from the top left corner. The former can be used as-is because the game uses the same format. But if your software counts pixels starting from the upper left corner, you should not use them directly. Instead, subtract your resulting coordinates them from 1. E.g. if your y-coordinate is 0.3, you would use 0.7 (1 – 0.3).

You may want to add 0.5 to the first x and y coordinates and subtract 0.5 from the second x and y coordinates. The game uses pixels as reference and the pixels calculated from xml coordinates are in between the exact coordinates. (1st pixel is between 0 and 1, second is between 1 and 2, etc). This will prevent your images from being clipped incorrectly from the edges. Using this technique, the example used previously would become: u1 = 250.5/1024 (or 0.24463), u2 = 299.5/1024 (or 0.29248), v1 = 100.5/1024 (or 0.09814), and v2 = 199.5/1024 (or 0.19482).


Remember that texture files need to have dimensions (length and width) of the power of two. (16, 32, 64, etc). However, the length and width do not need to be equal to each other. (One can be 16 and the other 32)

Instead of trying to fit images correctly in those dimensions, you can make the files bigger than they need to be, then scale them down accordingly. The coordinates in xml files do not need to be altered when the file size is scaled uniformly. E.g. A file scaling it’s width from 1024 to 512 doesn’t need to change it’s images coordinates because 100/1024 is the same as 50/512.