Free/Flexible tile map? (SOLVED)

Hi there, haven’t defolded for a long time … And actually I should ask this question pretty earlier.

At present the tiles in a tile map must stick to the grid - each tile’s top-left coordinate must be an integer multiple of the unit width (relative to the top-left of the whole map). It can’t shift a little bit (e.g. half of the unit width or 1px) . In other words, tiles are not allowed to be placed freely in a map. So, is it still possible to realize a tile map that may contain freely placed tiles?

A more general question is: How can one precisely control every tile when he wants, like supplying a script to let the tiles have some behaviors (give each tile a possibility to be “alive”)?

A scheme could be, to set everything as game objects instead of using a tile map (and to develop a custom map format on one’s own). But it’s like a waste of the tile map feature and more important is, when the map becomes bigger (e.g. maps in a serious game work) - to my feeling - there will be too many game objects to handle with. A mixed scheme, namely to use tile map for the “dead” tiles and game objects for the “living” (movable) tiles, is not so suitable here, because here we’re talking about the possibilities of every type of tiles, not only e.g. moving platforms.

A perfect example with this effect is the game Geometry Dash (which uses Cocos2d-x, though). Any block can have a precise position shift regardless of the grid, and can be controlled by “commands” (scripts), so the level editing is quite free and one can do detailed things.

Can we achieve such an effect in Defold? (Perhaps this requirement is too ideal and strict, but it would be really cool when we could realize it.)

No, the tilemap is designed specifically to place tiles in a fixed grid.

I would try this actually. And implement some sort of manual culling to disable objects that are out of view.

1 Like

In my mind, I see a Zelda like dungeon crawler where certain floor tiles come alive and start attacking the player.
FOr this I’d still use a tilemap, and then spawn separate game objects for the objects that need to move. So, in short, a combination of both tilemap and gameobjects.


@britzl Disabling objects out of view can cause problems, if objects still have to update even when we can’t see it. For example, I want something that keeps moving right. Suppose the player moves to a place where the camera doesn’t catch the moving object, like some distance to its right. At moment the moving object can’t be seen, but after the player has stayed here for a while, the object will eventually move into the view. On the other hand, its movement will stop if we disable it, and it can never be seen if the player doesn’t move. All the objects whose update has something to do with the time are like this case. And then the design of the map is totally destroyed.

@Mathias_Westerdahl Indeed I have considered a combination (as I said). But I have also thought of the possible maps that need a lot of game objects to replace tiles. Generally speaking, a mixture is inconvenient - it asks the logic to change very often, and, everything in a map is not unified.

Apologies if I’m incorrect, but I think britzl meant visual culling. This is a technique to lessen draw time by skipping geometry that the player cannot see. All objects continue to update, but not draw.


Cool technique. Does Defold do this by itself or I must realize it manually?

By the way, does anyone know clearly about something like how the amount of game objects influences the performance of the game? Although the visual culling can be used, sometimes there’re still too many game objects inside the view (e.g. when it zooms out) - or, this won’t happen in normal cases?

You have to implement visual culling manually. You can upvote this issue on GitHub (give it a thumbs up), which if implemented could be a useful tool.

Generally speaking, game objects are very cheap. It’s the components that are expensive, usually. In my game I rolled my own tile map system, where each component only has a sprite. Because of my inexperience at the time, I have struggled with performance in that game. If you design it well, and implement some sort of culling, you will be fine. I think if each tile has a script component with an update() step you are very likely to run into performance problems, so you’d likely have to come up with a different solution in that case.

1 Like

Thanks for your reply! I decided to build the map using game objects now.

You can check this little benchmark example which tests performance of game objects under various conditions (with a script on each, using a single script to update all, using go.animate() to let the engine move them etc)

WEB: Bunnymark 1.0
CODE: GitHub - britzl/defold-bunnymark: Defold bunnymark test

Defold can easily handle thousands of game objects in a web build and a couple of tens of thousands on desktop.


This is an awesome little project. Thanks for sharing. :slight_smile:

1 Like