#How to set alternative tiles in a TileSet with GDScript?

11 messages · Page 1 of 1 (latest)

rancid estuary
#

Hello!

I'm writing a GDScript script to generate a TileSet and a TileMap using said tile set, I've gotten to the point that most of it is working properly. My only obstacle now is, looking through the Godot docs, I can't find a way to set alternative tiles that are flipped vertically and/or horizontally.
So I see there is the method TileSetAtlasSource.create_alternative_tile(atlas_coords, uid), but I can find no way to modify/flip these alternative tiles.

link to docs where I found the create_alternative_tile: https://docs.godotengine.org/en/stable/classes/class_tilesetatlassource.html#class-tilesetatlassource-method-create-alternative-tile

Any help appreciated!

steel flame
#

Once you have created the alternate tile, you can use get_tile_data on TileSetAtlasSource to retrieve the TileData. This has properties flip_h, flip_v, transpose which you can set how you like.

However, if you're using Godot 4.2 dev 5 or later, and you just want to flip/rotate tiles, you don't need to create alternate tiles at all. There are some flags you can use with the alternate tile value that cause the tile to be flipped/rotated. For example,

myTileMap.set_cell(layer, coord, source, atlas_coord, alternate | TileSetAtlasSource.TRANSFORM_FLIP_H | TileSetAtlasSource.TRANSFORM_TRANSPOSE)

That will place a tile rotated 90 degrees counter-clockwise (h-flip and transpose).

rancid estuary
#

oh thanks! I think coming from other programming languages I assumed get_tile_data would return immutable data.

if that's how it is, I can't wait for Godot 4.2 to come out fully!

steel flame
rancid estuary
#

oh nice!

mint nova
#

Was struggling to place rotated tiles without manually creating alternative tiles, but now i don't even need to create alternative tiles! I love that you can keep the data of the tile, and it rotates the collision polygon too!

mint nova
# steel flame The dev snapshots are fully usable if you want to get started with them. The lat...

Pardon the second ping but I feel like you're the best person I can think to ask. Is this a bug, or am I doing something wrong?

The first input, places a tile at runtime, at its (natural) rotation, facing up.

The second input, places that same tile, bus uses the TileSetATlasSource flags to place a transposed and flip version. Note how only the last-placed tile has a Collision Polygon (the blue arrow-shaped one).

Some simple testing suggests that custom tile data is NOT lost, but the collision polygon goes bye-bye.

Is this an engine bug?

...and it looks like it is. While typing this I found this issue. It appears this is basically what I am facing right now: https://github.com/godotengine/godot/issues/83825

But I do want to ask someone more knowledgeable just to be sure that it is a bug and not something I could be doing wrong. If it is a bug, is it worthwhile sending this footage to that Github issue? Is it worthwhile applying a band-aid workaround for the meantime that copies and manually places a collision polygon?

GitHub

Godot version 4.2 beta 2 System information Pop Os 22.04 lts 12th Gen Intel® Core™ i7-12700H × 20 NVIDIA RTX A2000 8GB 32.0 ram. Tested on Forward+ and Mobile Issue description When painting a tile...

steel flame
#

oh, that's super broken

#

yeah hopefully that gets fixed before 4.2 is released

#

I imagine it will, seems like it's already understood in the ticket you linked