TileD tilemap, rendering isometric tiles
Monkey Forums/Monkey Programming/TileD tilemap, rendering isometric tiles
| ||
| Hiya! I have a little problem here... And I can't figure out what's causing it. I'm coding a game engine (just because I like technical coding) that supports TileD tilemap format. Rendering orthogonal tilemaps works fine, getting the correct tiles for each GID, but with this isometric test, I get somewhat confused and can't really explain what happens... So I'll help you out with images and code: My tilemap in the editor and running on my engine: ![]() Screenshot showing how the tiles are arranged in the tileset: ![]() The tilemap renders as it does in TileD, but I can't figure out why the tiles are so weirdly off... Isometric rendering method and RenderTile(): Method RenderIsometric:Void()
'note: Needs a screen-clipper
Local x:Int, y:Int, gid:Int
Local _x:Float, _y:Float, halfTileW:Float = tileWidth * 0.5, halfTileH:Float = tileHeight * 0.5
For y = 0 To parent.map.height - 1
For x = 0 To parent.map.width - 1
_x = (y * halfTileW) - (x * halfTileW)
_y = (x * halfTileH) + (y * halfTileH)
gid = data.GetTileID(x, y)
RenderTile(gid, _x, _y)
Next
Next
End
....
Method RenderTile:Void(gid:Int, x:Int, y:Int)
Local tileset:= parent.map.GetTilesetForGID(gid)
If tileset = Null Then Return
If tileset.image = Null Then Error("RENDER: Image for tileset '" + tileset.name + "' has failed to load!")
gid -= tileset.firstGID
Local idX:Int = (gid mod tileset.width) * tileset.tileWidth
Local idY:Int = (gid / tileset.width) * tileset.tileHeight
DrawImageRect(tileset.image, x, y, idX, idY, tileset.tileWidth, tileset.tileHeight)
EndMethod to get corresponding tileset for GID: Method GetTilesetForGID:TiledTileset(gid:Int)
Local set:TiledTileset
For set = EachIn tilesets.Values()
If gid >= set.firstGID And gid < set.lastGID
Return set
EndIf
Next
Return Null
EndMethod for getting tile ID: Method GetTileID:Int(x:Int, y:Int)
If width = 0 Then Return - 1
Return tiles.Get(y * width + x)
EndIf you spot _anything_ worth mentioning, I'd appreciate it very much. Thanks in advance. ~misthema |
| ||
| Have you tried loading your map using the Diddy TileD renderer? Looking at your screenshots, it looks like the wrong tile is being drawn. |
| ||
| No, haven't tried that - yet. But with orthogonal tilemaps, it was able to draw the correct tiles for each GID in tilemap. But with this isometric test, it does not.. That's why I posted my problem here, because it doesn't make any sense.. :D I'll report back once I've tried it with Diddy. EDIT: Ok, it looks like there's something wrong with my code somewhere.. Since Diddy did it, just fine: |
| ||
| Awesome, I got it working correctly. Should have looked the render coordinates straight... Old coordinates: _x = (y * halfTileW) - (x * halfTileW) _y = (x * halfTileH) + (y * halfTileH) Correct coordinates: _x = (-y * halfTileW) + (x * halfTileW) _y = (x * halfTileH) + (y * halfTileH) "Stupid mistakes are hardest to find..." |

