Reading XML SpriteSheet Maps

Here is a simple code to read XML Sprite sheet maps. It will extract the coordinates of all images in the Sprite sheet from a XML file generated with Sprite Vortex. We will use OmniXML to accomplish this task.
The following code will open a dialog to select an XML file extract the coordinates only, then list them in a memo component and save them to a text file.

This is how a XML Sprite sheet map looks like:

Spritemap screenshot

Sprite Map generated with Sprite Vortex

Under the Sprite tag you’ll find the Coordinates witch contain the info that we need to locate our animation frame or cell in the form of X, Y, Width and Height. The following code will extract those parameter and save them to a text file:

procedure TForm1.GoGetTheCoordinatesClick(Sender: TObject);
  descNode: IXMLNode;
  iNode   : integer;
  node    : IXMLNode;
  nodeList: IXMLNodeList;
  xml     : IXMLDocument;
  Lista: TStringList;
  s: String;
if opendialog1.Execute then

Lista:= TStringList.Create;
s := OpenDialog1.FileName;
s := ChangeFileExt(s, '.txt'); {will return the myfile.txt}
  xml := CreateXMLDoc;
  if XMLLoadFromFile(xml, OpenDialog1.FileName) then begin
    nodeList := xml.SelectNodes('//Coordinates');

    for node in XMLEnumNodes(xml, '//Coordinates') do
    memo1.Lines.Add(GetNodeTextStr(node, 'X')+' '+GetNodeTextStr(node, 'Y')+' '+GetNodeTextStr(node, 'Width')+' '+GetNodeTextStr(node, 'Height'));
    Lista.Add(GetNodeTextStr(node, 'X')+' '+GetNodeTextStr(node, 'Y')+' '+GetNodeTextStr(node, 'Width')+' '+GetNodeTextStr(node, 'Height'));

Some alternatives to OmniXML, are OXml and NativeXML

In the future We probably will explore integrating Box2d or the Chipmunk physics engines.

Have a nice day.

Mapping Spritesheets

Sprite Vortex make it easy to import sprite-sheets to create sprite maps

Sprite Vortex make it easy to import sprite-sheets to create sprite maps


To create sprite-sheets maps there are some commercial packages named Texture packers, also there are some free open source projects like Sprite Vortex by Rafael Vasco, written in C#.

FireBlaze requires 2 files to load and animation, the spritesheet, a png image with all the animation frames, and spritesheet map in a text file. The map file will list all the position and size of the frames as follow:

X Y Width Height
7 6 114 76
137 6 126 74

Sprite Vortex export XML Spritesheets maps but it can be tweak to export to a Text file map. Or your can read the XML files and extract the coordinates needed for you FireBlaze animation.