I want to store the patterns created by procedural content generation algorithms in the patterns of my TileMap via code so they appear in the dock window below.
Is there a way to add a new TileMapPattern to the patterns of the TileMap?
I can’t find a method for it, but maybe there’s a workaround.
If there’s no way to do this, is this feature planned for the near future?
var tile_map_pattern_size := Vector2i(16, 16)
var tile_map_pattern := TileMapPattern.new()
tile_map_pattern.set_size(tile_map_pattern_size)
for used_cell in get_used_cells(0):
if used_cell.x > map_position.x + tile_map_pattern_size.x or used_cell.y > map_position.y + tile_map_pattern_size.y:
continue
var atlas_coords := get_cell_atlas_coords(0, used_cell)
tile_map_pattern.set_cell(used_cell, 0, atlas_coords)
## works as expected
print(tile_map_pattern.get_used_cells())
var atlas_coords := []
for used_cell in tile_map_pattern.get_used_cells():
atlas_coords.append(tile_map_pattern.get_cell_atlas_coords(used_cell))
print(atlas_coords)
# add the tile_map_pattern to the patterns of this tilemap somehow...
Make sure to include the least amount of files that still cause the bug in your project with the bug report. That will help pinpoint the issue. Some threading race condition is my guess.
I managed to create a TileMapPattern just fine, the shape and position is expected, except the tile that are placed in the tilemap are “empty”.
var size = Vector2i(3,4)
var pattern = TileMapPattern.new()
pattern.set_size(size)
for x in range(size.x):
for y in range(size.y):
pattern.set_cell(Vector2i(x,y), 0, Vector2i(4,0))
set_pattern(0, Vector2i(1,1), pattern)
I fail to understand what to do.
is add_pattern required?
(4,0) is the tile atlas coord
I have the feeling instantiating TileMapPattern myself may not be the intended usage, maybe I should create pattern with other functions?