Hey. I've been working on this class for one of my own projects to add fuller support for the tmx format. Currently I have most of the tags supported (transparency, visibilty, spacing etc), base64 decoding and zlib compression - when I have support for polygons completed I shall share what I have. To solve the margin problem I did this:
//check tileset spacing if it exists
m_spacing = (tilesetElement->Attribute("spacing")) ? atoi(tilesetElement->Attribute("spacing")) : 0;
m_margin = (tilesetElement->Attribute("margin")) ? atoi(tilesetElement->Attribute("margin")) : 0;
//tiles/subrects are counted from 0, left to right, top to bottom
for (int y = 0; y < rows; y++)
{
for (int x = 0; x < columns; x++)
{
sf::Rect <int> rect; //must account for any spacing or margin on the tileset
rect.top = y * (m_tileHeight + m_spacing);
rect.top += m_margin;
rect.height = m_tileHeight;
rect.left = x * (m_tileWidth + m_spacing);
rect.left += m_spacing;
rect.width = m_tileWidth;
subRects.push_back(rect);
}
}
HTH