TileMap uses the same tile on tileset boundaries

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jcarvajal288

I’m following this tutorial: https://www.davidepesce.com/2019/10/18/godot-tutorial-7-using-tile-maps-to-create-game-map/

He makes a grass tileset using four tiles and assigns each equal priority of 1/4.

But when he paints the map using the grass tileset, note how at the boundaries of the map every tile uses the same sprite with blades of grass, ignoring the priorities. The inside of the map behaves as expected, with a mix of tiles.

How do I get the edge of the tileset to obey the priority distribution the way the inner tiles do?

I have a better solution for you.

You can use atlas mode and enable priorities. I found the answer here.
New tile type for selecting a random tile from an atlas without auto tiling. · Issue #24549 · godotengine/godot · GitHub

enter image description here

magnes3d | 2021-03-12 04:06

:bust_in_silhouette: Reply From: denxi

The reason that’s happening is because the tiles on the edges don’t have any matching bitmask tiles. When that happens, it defaults to using whatever tile you have set as the icon tile.

A better way to have that effect would be to also create bitmasks for the edge tiles, so rather than be filled in by default, you can actually set those tiles yourself.

I’m not sure what you mean by your second paragraph. All tiles in the tileset have bitmasks already, edge or no. Sure, I could manually place the edge tiles, but that defeats the point of an autotiler, no?

Really what I want is a way to ignore bitmasks entirely. That grass tileset shouldn’t care about what surrounding tiles are, it should just pick a tile at random.

jcarvajal288 | 2020-02-09 03:52

Bitmasks work by trying to match colour to colour, and non colour to non colour. In the example you gave, the only bitmasks that were marked for the grass tiles were:

[X][X]
[X][X]

Which means they’ll only be selected as an appropriate tile when surrounded by tiles on all sides. Edge tiles will look like this (on a 2x2):

[ ][ ]      [X][ ]      [X][X]     [ ][X]
[X][X]  OR  [X][ ]  OR  [ ][ ]  OR [ ][X]

When the autotile goes to place an edge tile, it checks for the appropriate bitmask. If it doesn’t find any that fit, which in this case it won’t, it instead selects whatever the default, icon tile is set to.

If I’m creating an autotile where I want the edge tiles to be the same as the middle tiles, I use 5 of the same image. One for the middle, and one for each of the four edges. If I want to have multiple, random middle tiles, then I’ll just add more, different images, and set their bitmask to the “middle” setting, aka the first one I wrote.

denxi | 2020-02-09 13:52

Ok, so it sounds like TileMap can’t do what I want it to do without a large number of copies of every tile in my tileset. That’s unfortunate. Thanks for your explanation.

jcarvajal288 | 2020-02-09 19:07