Can Defold handle hex based maps? (SOLVED)


G’day, Im looking at making a computer version of a board game as an inexperienced C# programmer. Its probably too big a task for me, game engine or no - twelve months ago I started working on making business logic in C# and learned a lot about the language I didnt know, but didnt actually get it working.
Im looking at Defold and Id like to take another crack at this project using Defold, but Im curious about whether Defold can handle the hex based map Ill need to use for this game. I was using a library to handle the hexes when I last had a go at this project, but Im not sure that would work with Defold.

I did have a look at the FAQs mentioned above to see if there was anything in them about grids, but unfortunately the link is broken!



There is no built in hex grid support but you can create it yourself using the standard components. @selimanac and @Dragosha are doing this:

1 Like


Oh, I’ll fix this!



AFAIK you should be able to create anything yourself with game components.

This is a very good read about implementing a hex grid.



It is! Thats the library I was using in my earlier efforts on this project, actually.



Which link was broken?



Its disappeared now. It was pinned to the top of the forum, below the current announcement, welcoming me to the forum and suggesting I read the FAQs before posting.

The link was to and it was near the bottom of the post. Seeing as its vanished now, I am guessing that perhaps its specific to new users?



Hex grids are not the something related to engines. It is just a logic. You can use hex grids almost every engine.
I’m using Tiled to edit the grid for now. You can simply export and parse the json file.
It isn’t so hard to parse the json but Tiled coordinate system is different than Defold, you should consider this.



tiled is free and it’s really, REALLY useful for this sort of thing. I used it for my grid-based game (exporting lua tables). And, yes, it would be easy to create a hex grid (it’s basically a square grid but every other row is offset by 0.5, it’s not something crazy)



I’ve been experimenting with Hex grids in Defold lately as well. I am NOT strong in math, or in code, and I’ve managed to get a working prototype complete with some basic A*

2 Resources I can not recommend enough:

for basically everything related to layout and coordinates of the hex grid (I used the “cube coordinates” method detailed here, flat-top version)


used to create the actual tile sprites, as well as the custom .convexshape collider

I have each tile as a game object with the custom collision shape, for mouse-over detection. There may be a better way, but this suits me fine.

edit sorry, didn’t notice the redblob site was already linked! oh well! it’s a great resource for this in any case!



Hi ryanscottlandry,
I was searching for a hex grid system like you did. Can you please share this code sample with hex grid system…



I’m not sure if anyone has anything packaged into a reusable piece of code to handle hex grid. But I bet you can get far by using game objects for the individual hexagons and some of the algorithms presented in the blog post above to handle calculations.

1 Like


I am new in Defold. I tried to develop a game using android studio (java) and I followed " Red Blob Games: Hexagonal Grids" tutorial too. There are some issue in that game (Pan and Zoom not working properly). Recently I installed Defold and trying to develop the same game. Now, I am learning tilemap and tilesource to implement this grid. I think, creating a GO for each hex will be more expensive. Anybody can help me…

This is what I developed in android studio.

1 Like


It is not expensive at all. You can use it safely. You can simply loop through an array and change the positions (x,y) of the grid gameobjects.



Game objects are not expensive. You should be totally fine to use game objects with a spirit for each hexagon.



Thank you for your reply,
Is it possible that to create multiple sprint ( hex image ) from a single image using script ? Or manually create sprite for each hex ( if its 8*8 total 64 hex image/sprite ) ?



Yes. You can easily create and position game objects with sprites using GO factories. You can also use maths to put each hex in the correct space.



Hi 8.josh,

You can easily create and position game objects with sprites using GO factories.

Can you share any code snippet or related article for doing that. I have only created GO by right clicking on that collection.

You can also use maths to put each hex in the correct space.

Yes, I am confident to do logic for that as of now. I am wondering how to create multiple GO or sprite using script. I could use position with single image, but here, I need multiple GO/sprite using single image.



What you are looking for is a factory component that can be used to spawn game object instances:




Thank you very much,
Let me play with these things :slight_smile:

1 Like