white borders around physicsbody of tiles in tileMapNode

263 Views Asked by At

I have a tileMapNode in which I want to assign a physics body to some tiles. I use the following function:

static func addPhysicsBody(to tileMap: SKTileMapNode, and tileInfo: String){

    let tileSize = tileMap.tileSize
    let halfWidth = CGFloat(tileMap.numberOfColumns) / 2 * tileSize.width
    let halfHeight = CGFloat(tileMap.numberOfRows) / 2 * tileSize.height

    for column in 0..<tileMap.numberOfColumns{
        for row in 0..<tileMap.numberOfRows{
            let tileDefinition = tileMap.tileDefinition(atColumn: column, row: row)
            let isCorrectTile = tileDefinition?.userData?[tileInfo] as? Bool
            if isCorrectTile ?? false && tileInfo == "wall"{
                let x = CGFloat(column) * tileSize.width - halfWidth
                let y = CGFloat(row) * tileSize.height - halfHeight
                let rect = CGRect(x: 0, y: 0, width: tileSize.width, height: tileSize.height)
                let tileNode = SKShapeNode(rect: rect)
                tileNode.position = CGPoint(x: x, y: y)
                tileNode.physicsBody = SKPhysicsBody.init(rectangleOf: tileSize, center: CGPoint(x: tileSize.width / 2, y: tileSize.height / 2))
                tileNode.physicsBody!.isDynamic = false
                tileNode.physicsBody!.restitution = 0.0
                tileNode.physicsBody!.categoryBitMask = Constants.PhysicsCategories.wall
                tileNode.physicsBody!.collisionBitMask = Constants.PhysicsCategories.player | Constants.PhysicsCategories.npc
                tileMap.addChild(tileNode)
            }
        }
    }
}

This all is working well, but if I run the app now, the tiles where I assigned a physics body to, have white borders. view.showphysics is set to false. Anyone an idea why there are white borders around the tiles? It looks like this:

enter image description here

0

There are 0 best solutions below