hsnabn wrote:
Good stuff you've got here. It's going to be useful, since I do use Tiled.
Thanks! Good to hear.

hsnabn wrote:
I'm especially interested in the final rendering code, as I've got this SVG rendering side project I'm trying to get to work.
I'm going with the low-level stuff Duality has to offer. Here's what I have so far (it's working, but only shows white tiles hehe):
Code:
public void Draw( IDrawDevice device )
{
if( GameObj == null || !_loaded || Layers == null || Layers.Count == 0 )
return;
Vector3 tempPos = GameObj.Transform.Pos;
float tempScale = 1f;
device.PreprocessCoords( ref tempPos, ref tempScale );
int halfMapW = W / 2;
int halfMapH = H / 2;
var vertices = new VertexC1P3T2[4];
for (var i = Layers.Values.GetEnumerator(); i.MoveNext();) {
var layer = i.Current;
if (!layer.Visible)
continue;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
// Is renderable tile available?
int gid = layer.GetTile(x, y);
if (gid <= 0)
continue;
// Get the correct tileset for this GID
var tileset = TiledTileset.FindByGID(gid);
if (tileset == null)
continue;
int tileX = (gid - tileset.FirstGID) % tileset.W;
int tileY = (gid - tileset.FirstGID) / tileset.W;
var uvRect = new Rect((tileX * TileW) / tileset.WPixel, (tileY * TileH) / tileset.HPixel, (tileX * TileW + TileW) / tileset.WPixel, (tileY * TileH + TileH) / tileset.HPixel);
int posX = (x - halfMapW) * TileW;
int posY = (y - halfMapH) * TileH;
// Top-left
vertices[0] = new VertexC1P3T2();
vertices[0].Pos.X = posX - (TileW / 2);
vertices[0].Pos.Y = posY - (TileH / 2);
vertices[0].Pos.Z = tempPos.Z;
vertices[0].TexCoord = uvRect.TopLeft;
vertices[0].Color = ColorRgba.White;
// Top-right
vertices[1] = new VertexC1P3T2();
vertices[1].Pos.X = posX + (TileW / 2);
vertices[1].Pos.Y = posY - (TileH / 2);
vertices[1].Pos.Z = tempPos.Z;
vertices[1].TexCoord = uvRect.TopRight;
vertices[1].Color = ColorRgba.White;
// Bottom-right
vertices[2] = new VertexC1P3T2();
vertices[2].Pos.X = posX + (TileW / 2);
vertices[2].Pos.Y = posY + (TileH / 2);
vertices[2].Pos.Z = tempPos.Z;
vertices[2].TexCoord = uvRect.BottomRight;
vertices[2].Color = ColorRgba.White;
// Bottom-left
vertices[3] = new VertexC1P3T2();
vertices[3].Pos.X = posX - (TileW / 2);
vertices[3].Pos.Y = posY + (TileH / 2);
vertices[3].Pos.Z = tempPos.Z;
vertices[3].TexCoord = uvRect.BottomLeft;
vertices[3].Color = ColorRgba.White;
device.AddVertices(tileset.Image, VertexMode.Quads, vertices);
}
}
}
}
Not sure if I'm doing this correctly, but at least the tiles are all in place. Just need a little tweaking with the UV-coordinates...

Also, there's some funny bugs in it.
http://puu.sh/lvWZJ/f4d9b2c843.pngAlso updated an image link to the first post about the data it stores atm!