0

I am playing around with SpriteKit and the TileMapNode and i've got an annoying problem.

That's how it should look like. enter image description here

That's how its actually looking in the simulator/device.

enter image description here

The white spaces are terrible and i have no idea, how to get rid of them. My Tiles are about 70x70 in the "Sprite Atlas - Part" of the assets, i've configured my tilemapnode with a scale of 0.5 and tile size of 70x70.

While testing some cases, i figured out that this part of code triggers the error, but i have no idea, what could be wrong. Changing the SKPhysicsBody size to a smaller one, did not helped.

guard let tilemap = childNode(withName: "LevelGround") as? SKTileMapNode else { return }            
let tileSize = tilemap.tileSize
        let halfWidth = CGFloat(tilemap.numberOfColumns) / 2.0 * tileSize.width
        let halfHeight = CGFloat(tilemap.numberOfRows) / 2.0 * tileSize.height
        for row in 0..<tilemap.numberOfRows {
            for col in 0..<tilemap.numberOfColumns {
                if tilemap.tileDefinition(atColumn: col, row: row) != nil {
                    let x = CGFloat(col) * 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(rectangleOf: CGSize(width: 70, height: 70), center: CGPoint(x: tileSize.width / 2.0, y: tileSize.height / 2.0))
                    tileNode.physicsBody?.isDynamic = false
                    tileNode.physicsBody?.collisionBitMask = 2
                    tileNode.physicsBody?.categoryBitMask = 1
                    tileNode.physicsBody?.contactTestBitMask = 2 | 1
                    tileNode.name = "Ground"
                    tilemap.addChild(tileNode)
                }
            }
        }
  • where your scene is loaded (usually from the viewController). set showPhysics to true. It should show you where your alignments are off. – Goodtime Apr 18 '17 at 17:12

1 Answers1

0
tileNode.strokeColor = .clear

solved the problem

Update: problem not solved... just moved :/

When checking, if ground & player are in contact, every new tile the status is switching between "contact" and "no contact". When using a cube instead a circle, the cube begins to rotate. It seems, the corner of the cube get's stuck at the minimal space between the tiles.