creating data for a tile isometric game?

Hello…

I just found a program called “Tiles”

I create a map. exported the map for corona SDK.

I have a .lua file open in my Editor.

I see a table

return {

– here there are a lot of tables with info

– terrain, layers, size of tiles and so on

}

there is one table called “data” similar to this

data = {         24, 24, 23, 11, 19, 19, 12, 23, 24, 24, 23, 7, 2, 2, 1, 4, 2, 2, 3, 4, 4, 1, 3, 4, 1,         4, 2, 3, 2, 1, 4, 2, 2, 1, 2, 2, 2, 4, 3, 3, 2, 3, 3, 2, 3, 2, 4, 1, 3, 1,         1, 1, 1, 4, 1, 3, 3, 2, 1, 4, 2, 1, 3, 1, 3, 3, 4, 3, 4, 2, 1, 2, 3, 1, 1       }

I think this is the order of each tile to form the actual map.


QUESTION 1


How do I do that in Corona SDK?

when I have a … for i loop … to lay all the tiles

local tiles = {} function createBoard1()         for i = 1, 20 do               for j = 1, 20 do          local aTile = display.newImageRect(sceneGroup, "images/grass1.png", 128, 64 )          tiles[i] = aTile -- For efficient instead of multiple lookups.          aTile:setMask( maskGrass1 )          floorGroup:insert( aTile )          aTile.isHitTestMasked = true                 aTile.x = 128\*(i-1)                      aTile.y = 64\*(j-1)          aTile.myID = (i-1) \* 20 + j          aTile.touch = onTouch          aTile:addEventListener( "touch" )       end        end end createBoard1()

because it just gives me 1 image

local aTile = display.newImageRect(sceneGroup, “images/grass1.png”, 128, 64 )

but I would like to put many different tiles to form the map


QUESTION 1


Or if you are familiar with “Tiles” program

How do I use that “return” table in composer?

Thanks for all your help

Do you “Tiles” with an S, or “Tiled” with a D? If you mean Tiled, there are a couple level editors/managers that use Tiled as a base. Check out Million Tile Engine, and Dusk Engine, as they are both useful in what I think you’re looking for.

Sorry… it was “D”

I will see those programs, thanks

Victor when you have an array with a single index like you are using, loops like:

for i = 1, 20 do     for j = 1, 20 do     end end

i will only be values of 1 - 20, though you have 400 items.  You need to calculate the index of your array based on a simple formula:

local index = ( i - 1 ) \* 20 + j tiles[index] = ....

However you may want to consider a 2 dimensional array for this. 

for i = 1, 20 do      tiles[i] = {} -- empty array      for j = 1, 20 do            tiles[i][j] = ....      end end

Rob

Hi Rob…

I didn’t really get your idea… never seen that

this works fine

local tiles = {} function createBoard1()         for i = 1, 20 do               for j = 1, 20 do          local aTile = display.newCircle(sceneGroup, 0, 0, 20 )          tiles[i] = aTile -- For efficient instead of multiple lookups.                aTile.x = 128\*(i-1)                      aTile.y = 64\*(j-1)          aTile.myID = (i-1) \* 20 + j          aTile.touch = onTouch          aTile:addEventListener( "touch" )       end        end end createBoard1()

This is NOT working

local tiles = {} function createBoard2() for i = 1, 20 do      tiles[i] = {} -- empty array      for j = 1, 20 do            tiles[i][j] = display.newCircle(sceneGroup, 0, 0, 20 )          tiles[i][j] = aTile                tiles[i][j].x = 128\*(i-1)                      tiles[i][j].y = 64\*(j-1)          tiles[i][j].myID = (i-1) \* 20 + j          aTile.touch = onTouch          aTile:addEventListener( "touch" )      end end end createBoard2()

and the main problem is how can I move, or rotate each image…

like tiles[231].rotation = 45

Thanks Rob…

Do you “Tiles” with an S, or “Tiled” with a D? If you mean Tiled, there are a couple level editors/managers that use Tiled as a base. Check out Million Tile Engine, and Dusk Engine, as they are both useful in what I think you’re looking for.

Sorry… it was “D”

I will see those programs, thanks

Victor when you have an array with a single index like you are using, loops like:

for i = 1, 20 do     for j = 1, 20 do     end end

i will only be values of 1 - 20, though you have 400 items.  You need to calculate the index of your array based on a simple formula:

local index = ( i - 1 ) \* 20 + j tiles[index] = ....

However you may want to consider a 2 dimensional array for this. 

for i = 1, 20 do      tiles[i] = {} -- empty array      for j = 1, 20 do            tiles[i][j] = ....      end end

Rob

Hi Rob…

I didn’t really get your idea… never seen that

this works fine

local tiles = {} function createBoard1()         for i = 1, 20 do               for j = 1, 20 do          local aTile = display.newCircle(sceneGroup, 0, 0, 20 )          tiles[i] = aTile -- For efficient instead of multiple lookups.                aTile.x = 128\*(i-1)                      aTile.y = 64\*(j-1)          aTile.myID = (i-1) \* 20 + j          aTile.touch = onTouch          aTile:addEventListener( "touch" )       end        end end createBoard1()

This is NOT working

local tiles = {} function createBoard2() for i = 1, 20 do      tiles[i] = {} -- empty array      for j = 1, 20 do            tiles[i][j] = display.newCircle(sceneGroup, 0, 0, 20 )          tiles[i][j] = aTile                tiles[i][j].x = 128\*(i-1)                      tiles[i][j].y = 64\*(j-1)          tiles[i][j].myID = (i-1) \* 20 + j          aTile.touch = onTouch          aTile:addEventListener( "touch" )      end end end createBoard2()

and the main problem is how can I move, or rotate each image…

like tiles[231].rotation = 45

Thanks Rob…