Topic was automatically imported from the old Question2Answer platform.
Asked By
wombatTurkey
Old Version
Published before Godot 3 was released.
Was just curious as I’m making a cool map reveal thing and using get_used_cells works great. However, the ability to change their alpha of a cell would be nice so we can transition them.
Thanks for reading!
I don’t understand well what you do with get_used_cells, but there is a way to change cells with tilemap.set_cell(x, y, tile_id).
There is no way of changing the alpha of tiles individually, but if you want to do a tile-based map reveal thing you can do it with a second tilemap that hides the first one with tiles made of several shades of black.
You can change tiles too with set_cell, x and y parameter refer to the tilemap grid.
Here is an example of a “static body” cell changed to a cell without collision: https://twitter.com/_eons/status/786620636210663424
Now about the alpha thing, you are working over a single texture and you can’t alter a region of it, you are talking about another tilemap or a sprite over the tilemap.
I know it has been a while, but I needed this too and came up with this solution, using a simple script attached to my tilemap. Note that the texture must be a sequence of all the frames (so a 64x32 image for 2 frames of size 32x32 for example). The region associated with the tileset will be ((0, 0), cell_size) and we want to translate that in time. So we just create a timer (its wait time will be the time between two consicutive frames) and attach this script to the tilemap:
extends TileMap
var nb_frames: int = 0
var current_frame: int = 0
func _ready():
nb_frames = tile_set.tile_get_texture(0).get_size().x / cell_size.x
func next_frame():
current_frame = (current_frame + 1) % nb_frames
tile_set.tile_set_region(0, Rect2(Vector2(current_frame*cell_size.x, 0), cell_size))
func _on_Timer_timeout():
next_frame()
Of course don’t forget to connect the timer to your tilemap.