This function can be used to set any cell (grid square) within the tilemap element on the layer to a new tile. You give the tilemap element ID (which you get when you create a tilemap element using layer_tilemap_create() or when you use the function layer_tilemap_get_id()), and then the tile data to set as well as the position within the tilemap. You can retrieve tile data using the function tilemap_get and then use the tile_ functions to change it before setting the cell using this function. The function will return true if the tile was successfully set and false if there was an issue and it wasn't set.
tilemap_set(tilemap_element_id, tiledata, xcell, ycell)
Argument | Description |
---|---|
tilemap_element_id | The unique ID value of the tilemap element to change |
tiledata | The tile data to set |
xcell | The cell (grid) position to set along the x-axis |
ycell | The cell (grid) position to set along the y-axis |
Boolean
var lay_id = layer_get_id("Tiles_sky");
var map_id = layer_tilemap_get_id(lay_id);
var data = tilemap_get(map_id, 0, 0);
data = tile_set_flip(data, true);
tilemap_set(map_id, data, 0, 0);
The above code gets the ID for the tilemap on the layer "Tiles_Sky" and then uses that to get the data from the tile at cell (0, 0). This tile data is then flipped before being used to set the tile on the tilemap again.