The commands are independent of map type, it'll handle it for you.
First thing is you have to call the _TMX_Init subroutine to initialize UDTs and other variables.
Command List:
tmx_LoadMap(filename)
tmx_FreeMap()
tmx_DrawMap(TMX_Map, offsetX, offsetY)
tmx_DrawGridTile(TMX_Map, pixelX, pixelY)
tmx_DrawGrid(TMX_Map, offsetX, offsetY)
tmx_GetTileAtPixel(pixelX, pixelY, offsetX, offsetY)
tmx_getPixelAtTile(tileX, tileY, offsetX, offsetY)
After calling getTileAtPixel or getPixelAtTile, the coordinates are stored in the global variable TMX_Mouse. See the code comments for further details.
So here it is. Enjoy!
Hold right mouse button to drag map around the screen.
Press 'G' to toggle grid.
Press 1-3 to switch between different maps
Press space key to end the demo.
Here's the main source file for the demo. The bulk of the code doing all the real work is broken down into two other files.
` \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
` \\ Title: TMX Demo
` \\ Version: 1.0 beta
` \\ Author: Phaelax
` \\ Data: May 2, 2013
` \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#include "xml.dba"
#include "tmx_engine.dba"
rem Initialize xml library
gosub _XML_Init
rem Initialize tmx library
gosub _TMX_Init
rem Collision box color
cbox as dword
cbox = 0x88FFFFFF
rem map offset
offsetX = 0
offsetY = 0
rem load default map
tmx_Loadmap("example.tmx")
repeat
cls
rem user controls
gosub _Controls
rem Draw the tile map
tmx_DrawMap(TMX_Map, offsetX, offsetY)
rem draw grid
if showGrid
ink rgb(92,92,92),0
tmx_DrawGrid(TMX_Map, offsetX, offsetY)
endif
rem Get grid coordinates for tile at mouse
tmx_GetTileAtPixel(mousex(), mousey(), offsetX, offsetY)
rem Get pixel coordinates for tile at mouse
rem Must call tmx_GetTileAtPixel prior to calling this
tmx_getPixelAtTile(TMX_Mouse.tileX, TMX_Mouse.tileY, offsetX, offsetY)
rem Draw grid outline around tile at mouse
ink rgb(0,255,0),0
tmx_DrawGridTile(TMX_Map, TMX_Mouse.x, TMX_Mouse.y)
rem display collision boxes, if any
for i = 0 to array count(tmx_CollisionData())
x = tmx_CollisionData(i).x + offsetX
y = tmx_CollisionData(i).y + offsetY
box x, y, x+tmx_CollisionData(i).width, y+tmx_CollisionData(i).height,cbox,cbox,cbox,cbox
next i
rem Display grid coordinates at mouse position
ink -1,0
print TMX_Mouse.tileX," : ",TMX_Mouse.tileY
print
print "1. Orthogonal"
print "2. Isometric"
print "3. Staggered"
until spacekey()
end
REM ===========================================
REM User controls
REM ===========================================
_Controls:
rem right-click to drag map around screen
if mouseclick() = 2
if moveFlag = 0
moveFlag = 1
oldMx = offsetX - mousex()
oldMy = offsetY - mousey()
endif
if moveFlag = 1
offsetX = mousex() + oldMx
offsetY = mousey() + oldMy
endif
else
moveFlag = 0
endif
rem press 'G' to toggle tile grid
if lower$(inkey$()) = "g" and vkFlag = 0
vkFlag = 1
showGrid = 1 - showGrid
endif
if inkey$() = "" then vkFlag = 0
if inkey$() = "1" and vkFlag = 0
vkFlag = 1
offsetX = 0
offsetY = 0
tmx_FreeMap()
tmx_Loadmap("example.tmx")
offsetX = 0
offsetY = 0
endif
if inkey$() = "2" and vkFlag = 0
vkFlag = 1
offsetX = 0
offsetY = 0
tmx_FreeMap()
tmx_Loadmap("isometric_grass_and_water.tmx")
endif
if inkey$() = "3" and vkFlag = 0
vkFlag = 1
offsetX = 0
offsetY = 0
tmx_FreeMap()
tmx_Loadmap("staggered.tmx")
endif
RETURN
"You're all wrong. You're all idiots." ~Fluffy Rabbit