#Help updating a tilemap's autotiling

28 messages · Page 1 of 1 (latest)

shadow hinge
#

Ive set up a tile set with working autotiling. In the editor, verything is perfect and the autotiling is done automatically whenever a add a new tile.
However ive got terrain destruction in my game and i need to update de autotiling. I wish to know how to do that.
Ive used set_cells_terrain_connect but it behaves really weird. If used on empty cells, it generates new cells (?) and only updates autotiling on the new cells (see gif).

shadow hinge
#

help pls

#

if set_terrain coonect is used to generate new tiles, it doesnt take in consideration tiles already present, so every time my bomb explodes id have to re-do the tiles for the whole map

#

sounds like terribly inefficient. Godot 3 had a way to update bitmap for only a section of the map, there must be a way to do so in G4

shadow hinge
#

bump

ivory basin
#

I responded to you in the channel you originally posted in with a possible explanation. The set terrain cells works with replicating neighbors, it seems that when the bomb explodes, it is looking for the cells and trying to make their neighbors to fill the area. I can see near where your player is, that's where the bomb radius seems to go off till and it has that type of tile.

shadow hinge
#

using set_cells_terrain_connect(background_layer, surround_cells, background_terrain_set, 0);, surround cells being the cells marked in red, this is what happens

ivory basin
# shadow hinge i dont understand, what would be the solution?

I don't work with tilesets that much so I'm not sure. But it seems to me that you can assign values to tiles and then from that you can try and avoid certain tiles with those values. Again, not much working knowledge with tilesets but set_cells_terrain_connect is trying to find neighbors from how it seems and connects with them by the rule you have defined.

#

Though, you can try linking this post in the main chat at a time when the discord is more active or right now, maybe someone else has a better explanation.

shadow hinge
#

bro i think i got it

#

jesus

shadow hinge
#

'# Destroy background
var center = local_to_map(pos);
var sq_rad = int(radius/Global.CELL_SIZE);
var destroyed_cells = [];
var surround_cells = [];
for x in range(-sq_rad,sq_rad+1):
for y in range(-sq_rad,sq_rad+1):
var p = center + Vector2i(x,y);
if map_to_local(p).distance_to(pos) <= radius:
erase_cell(background_id,p);
_erase_pixels_background(b_block_matrix[p.x][p.y]);
destroyed_cells.append(p);
for p in destroyed_cells:
var surr = get_surrounding_cells(p);
for c in surr:
if get_cell_source_id(background_layer, c) != -1 and !c in surround_cells:
surround_cells.append(c);
Global._marker(world, map_to_local(c));

set_cells_terrain_connect(background_layer, surround_cells, background_terrain_set, -1);
set_cells_terrain_connect(background_layer, surround_cells, background_terrain_set, 0);
#

when i want to update i must first assign no terrain (-1) and then change it to the terrain I want... but only in the border of the explosion. If I call it on all involved tiles the hole closes (generates new tiles where there wanst a tile)

#

so set_cells_terrain_connect actually generates a tile on the position specified

ivory basin
#

What you can try is have a collision shape on the bomb, and check what that collision shape overlaps to. As soon as character places the bomb, mark all areas in that collision shape with a value that denotes they are destructible. And then when the bomb explosion is trigerred, just do you animation and perform desired action on all tiles that were marked with that value.

so if collision shape overlaps -> set destructible = true and then when bomb.explosion = true go through tiles with destructible set to true and just get rid of them or perform whatever action you want.

#

That way you probably won't have this lag issue you're facing, its likely because of the nested looping and calculations therein

#

Of course, when the bomb changes places, or is picked back up, you call the collision shape's exited function and flip the destructible value on tiles so they no longer get affected

shadow hinge
#

i was having lag cus i was calling set_cells_terrain_connect on the entire map. It worked taht way but huge lag. Now ive limited the calls to only border cells.

#

so theres no lag

shadow hinge
#

to see what tilles are inside

ivory basin
shadow hinge
#

i just dont know if im doing it the right way but it works with no lag, but im using 2 calls (maybe its possible using only 1)

#

set_cells_terrain_connect(background_layer, surround_cells, background_terrain_set, -1);
set_cells_terrain_connect(background_layer, surround_cells, background_terrain_set, 0);

#

iuse 1 call to delete cells and another to re-create them