#What are the requirements for tilesets to be swappable?

1 messages · Page 1 of 1 (latest)

lament ivy
#

I am experimenting with tilesets and noticed that replacing one tileset with another is not necessarily possible, despite them being "fairly similar". The primary differences between the tilesets are the amount and types of alternative tiles defined by the same terrain, other than that they are similar enough which is noticeable as the resulting map after swapping tileset had some wall tiles at the correct spots with the new textures.

Having said that, what are the relevant details to ensure the tilesets can be swapped without issues?

lament ivy
#

From what I can guess, it looks like these separate atlas elements belonging to a single tileset have to have matching IDs (such as atlas_0_walls being always ID X across all tilesets). The issue though is if a particular tileset has an atlas for unique alternative tiles such as atlas_2_floor in this picture which contains a unique lotus on water this may not necessarily exist in other tilesets. This seems to be the reason of the issue in the first place. Of course I could use some code to programmatically copy the terrain type from one layer to a new one with the second tileset and have Godot rerender and pick suitable tiles and alternative tiles, but I was really looking to have this be somewhat automated whenever I just replace the tileset itself.

safe burrow
#

I do not think swapping tile sets is supported. But if you want to try. It seems that the TIleMap only stores the source_id and the atlas_coordinates. So if the other TileSet has the same amount of sources, each with the same amount of tiles, it may work.

lament ivy
#

Sadly this won't be the case as each tilemap can have a different amount of alternative tiles or even frames for animations. Given that you clarified it's not a dedicated feature it's indicative that I have to handle it programmatically as outlined earlier which is at least a solution during runtime. I'll look further into it then.

sacred light
#

If you are using terrains, you can regenerate the map after a swap as long as you know which tiles should have a tile there

#

#1328723519076302949 message

lament ivy
#

Oh that looks intriguing when it comes to generating a tilemap based on my generator. Will keep that in mind, just have to figure out how to read the existing terrain data from a layer (assuming it is even stored as terrain and not instantly flattened into the selected tiles).

lament ivy
#

@sacred light I managed to hack together an initial version of a copy script that copies the terrain from one layer to the other. Conceptually it works, but it's not performant and could be improved by grouping and batching, but it works for the time being.

var sourceMapLayer = GetNode<TileMapLayer>("SourceMap");
var destinationMapLayer = GetNode<TileMapLayer>("DestinationMap");

var usedRect = sourceMapLayer.GetUsedRect();
for (var x = usedRect.Position.X; x < usedRect.Position.X + usedRect.Size.X; x++)
for (var y = usedRect.Position.Y; y < usedRect.Position.Y + usedRect.Size.Y; y++)
{
    var coordinate = new Vector2I(x, y);
    var tileData = sourceMapLayer.GetCellTileData(coordinate);
    if (tileData != null)
        destinationMapLayer.SetCellsTerrainConnect([coordinate], tileData.TerrainSet, tileData.Terrain);
}
#

Your other post was helpful to quickly figure out how to draw the terrain dynamically. Thanks mate.

sacred light
#

Im not at a computer but I feel like there is a get used cells method to get a list of all cells with tiles