Hi all, and apologies if this has been answered before. My question is that can individual tiles in a tile map have logic or scripts attached to them? For example I want to procedurally generate a map with terrain and then I want to be able to terraform that terrain. Would it be better to have each tile be a game object / actor or would I be able to accomplish this with a tile map?
Thanks for the help and I hope my question make sense!
Basically I want to create maps like this, and then have the tiles be able to be swapped out with other tiles as needed, etc…
1 Like
I would use a tilemap and then a script that controls the logic of all of the tiles on the tilemap. I’m thinking a 2D array/table mapping between the tiles on the tilemap and the additional data you need to represent the tilemap content. You would operate on the additional data per tile and then update the tilemap to the correct representation.
1 Like
Thank you for your reply Britzl! So I understand a bit better for example does each tile have its own unique id that can be accessed through script and if I wanted to swap it out I can use another tile? Is this accurate? Thanks for bearing with me!
Not really. Each tile has an x & y coordinate and you can use tilemap.set_tile() (and tilemap.get_tile()) to interact with the tiles on the map.
1 Like
Sounds good. Thank you for the explanation! Trying to wrap my head around what’s possible with Defold and working with tiles. Going to work through more tutorials tonight. Really liking Defold so far. My background is with Unity so Lua is new to me but I like it so far. Thanks again for the help!
2 Likes
Don’t hesitate to ask here if you have more questions. Defold and Lua is quite different from Unity in several ways. Defold and Lua is not made for thinking in terms of OOP for instance. There is no script per individual tile in a tilemap for instance
Instead there’s a focus on structuring your data in a way that makes it easy to manipulate and this affects the way your write your code.
5 Likes
I think my brain might like this approach better! Thanks again for the support thus far. My fist impressions with Defold, the tutorials, the forums, interacting with the team have all been very positive. Keep up the good work!
2 Likes