I have an SKTileMapNode that I am filling with rooms using a BSP algorithm I translated into Swift from this tutorial. The fully translated algorithm can be found on my github repo
I have a custom class that gives me four corner positions of a room. I use the four corner positions to fill everything in the room like so:
for row in 0..<tileMap.numberOfColumns {
for column in 0..<tileMap.numberOfRows {
for room in rooms {
// iterate through each room and draw it in
if room.minX <= column && room.maxX >= column && room.minY <= row && room.maxY >= row {
tileMap.setTileGroup(tileGroup2, forColumn: column, row: row)
}
}
for hallway in hallways {
// iterate through each hallway and draw it in
if hallway.minX <= column && hallway.maxX >= column && hallway.minY <= row && hallway.maxY >= row {
tileMap.setTileGroup(tileGroup2, forColumn: column, row: row)
}
}
}
}
Where hallways
and room
are both arrays of my Room
class that holds the four corner positions.
class Room {
var minX:Int
var maxX:Int
var minY:Int
var maxY:Int
var center:CGPoint
init(X: Int, Y: Int, W: Int, H: Int) {
minX = X
maxX = X + W
minY = Y
maxY = Y + H
center = CGPoint(x: (minX + maxX) / 2, y: (minY + maxY) / 2)
}
}
I know how to fill everything inside the rooms, but how can I fill everything else outside the rooms? I can't seem to figure it out. And doing if room.minX >= column && room.maxX <= column && room.minY >= row && room.maxY <= row
always fails.
I need to fill everything that "leaks" outside the rooms because Apples SKTileMapNode auto-tiling is buggy and I need to "smooth" it out.
Examples of the buggy auto-tiling:
What they should be:
My thought process, because the auto-tiling doesn't work, is to fill everything that leaks outside the rooms and hallways with the black tiles. Hopefully, that should force the auto-tiling algorithm to properly place the tiles as 4-sided polygons. I can't figure out how to fill everything outside the rooms, however. My alternative option is to make an auto-tiling algorithm myself. I would like to avoid that because it would take days to make and it would be a hassle.