Trouble with tilemaps

Hi all, and happy new year.
I’m new to corona and lua

I’m working on a 2d Strategy game. I’ve managed to find some good working code to save and load json map files that I’ve created, and some code that will put the correct tiles on the screen, and even cull those that aren’t on the screen, and scroll the map on screen with touch.

What I need to figure out is how to make the individual tiles selectable. The don’t have to be actually selectable, but I need to know what tile was tapped by the player so I can then provide context correct options to the player, after which the changes are saved and the screen redrawn.

A small map is going to be 10 x 10 for 100 squares, and a large map will likely be around 400-500 squares.
Do I have to go at this problem differently, and make every tile an object? Intuitively, that sounds far more demanding on resources then creating some form of pointer or check procedure that can get me specific access to the tile tapped by the player.

Right now I have my maps saved as 3 dimensional array, or “table”. I’m storing y in one table, x in an another, and then TileType and TileOwner in the 3rd nesting. Actions taken by the player will effect both TileType, and TileOwner

Remember I’m new at this, so any helpful code you can provide is great, and comments explaining the tricky bits.

Thanks [import]uid: 170004 topic_id: 34457 reply_id: 334457[/import]

Check out this tutorial from one of the Corona Staff members:

http://www.infusedreams.com/2012/12/22/creating-a-grid-based-game-in-corona-part-1-2/

I have not used it or read it completely; I just briefed over it, but it appears well done, informative and easy to understand.
It is a good start, and a good way to learn and understand the code.

Good luck! [import]uid: 148857 topic_id: 34457 reply_id: 137020[/import]

I don’t think it’s going to be too resource heavy to add a touch handler to each tile since they are unique display objects. You only need one function and that function will know which tile was tapped as the varaible: event.target.

The other way to do it is to put a touch handler on the whole screen using a Runtime:addEventListener(“touch”, yourTouchFunction) call. You won’t get a usable event.target to identify which cell was tapped, but you would get the X, Y of the touch and you could calculate which cell was tapped.

[import]uid: 199310 topic_id: 34457 reply_id: 137027[/import]

Thanks cyberpark, I’ll give that a read.

Hi Rob, thanks for the reply.
I had set up a “tap” runtime event listener and already use it to collect x and y. While i understand the general concept behind what needs to happen from there, I haven’t worked the calculations out yet, it hurts a little.

Part of the problem is that I do not fully understand the code I’m using to put my map on the screen. I grabbed it from p120ph37 who posted it in http://developer.coronalabs.com/forum/2011/01/29/object-culling-render-process-when-not-content-area

I was concerned about the overhead of giving each tile a touch handler, but we’ve established I don’t know much, yet.

By the way Rob, I’m using your code to load and save my JSON map file, thanks for that. [import]uid: 170004 topic_id: 34457 reply_id: 137048[/import]

I doubt tap handlers on the off screen objects is going to add any significant overhead, but that 's speculation since I’ve never really tried it.
[import]uid: 199310 topic_id: 34457 reply_id: 137050[/import]

Check out this tutorial from one of the Corona Staff members:

http://www.infusedreams.com/2012/12/22/creating-a-grid-based-game-in-corona-part-1-2/

I have not used it or read it completely; I just briefed over it, but it appears well done, informative and easy to understand.
It is a good start, and a good way to learn and understand the code.

Good luck! [import]uid: 148857 topic_id: 34457 reply_id: 137020[/import]

I don’t think it’s going to be too resource heavy to add a touch handler to each tile since they are unique display objects. You only need one function and that function will know which tile was tapped as the varaible: event.target.

The other way to do it is to put a touch handler on the whole screen using a Runtime:addEventListener(“touch”, yourTouchFunction) call. You won’t get a usable event.target to identify which cell was tapped, but you would get the X, Y of the touch and you could calculate which cell was tapped.

[import]uid: 199310 topic_id: 34457 reply_id: 137027[/import]

Thanks cyberpark, I’ll give that a read.

Hi Rob, thanks for the reply.
I had set up a “tap” runtime event listener and already use it to collect x and y. While i understand the general concept behind what needs to happen from there, I haven’t worked the calculations out yet, it hurts a little.

Part of the problem is that I do not fully understand the code I’m using to put my map on the screen. I grabbed it from p120ph37 who posted it in http://developer.coronalabs.com/forum/2011/01/29/object-culling-render-process-when-not-content-area

I was concerned about the overhead of giving each tile a touch handler, but we’ve established I don’t know much, yet.

By the way Rob, I’m using your code to load and save my JSON map file, thanks for that. [import]uid: 170004 topic_id: 34457 reply_id: 137048[/import]

I doubt tap handlers on the off screen objects is going to add any significant overhead, but that 's speculation since I’ve never really tried it.
[import]uid: 199310 topic_id: 34457 reply_id: 137050[/import]