Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SKTileMapNode冲突不起作用_Ios_Swift_Sprite Kit - Fatal编程技术网

Ios SKTileMapNode冲突不起作用

Ios SKTileMapNode冲突不起作用,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我正在尝试使用SKTileMapNode和SKTileMaps制作一个侧卷轴,但是我在单个瓷砖的物理实体方面遇到了问题。我在循环中创建它们,如本链接所述: 然而,我的玩家节点穿过地面。我做错了什么 guard let landBackground = childNode(withName: "ground") as? SKTileMapNode else { fatalError("Background node not loaded")

我正在尝试使用SKTileMapNode和SKTileMaps制作一个侧卷轴,但是我在单个瓷砖的物理实体方面遇到了问题。我在循环中创建它们,如本链接所述:

然而,我的玩家节点穿过地面。我做错了什么

        guard let landBackground = childNode(withName: "ground")
        as? SKTileMapNode else {
            fatalError("Background node not loaded")
    }
    self.landBackground = landBackground
    self.tileSize = landBackground.tileSize

    for x in 0...(landBackground.numberOfColumns-1){
        for y in 0...(landBackground.numberOfRows-1){

            let tile = landBackground.tileDefinition(atColumn: x, row: y)
            if(tile != nil){
                let rect = CGRect(x: 0, y: 0, width: tileSize.width, height: tileSize.height)
                let tileNode = SKShapeNode(rect: rect)

                tileNode.position = self.landBackground.centerOfTile(atColumn: x, row: y)

                tileNode.position.x -= (tileSize.width * 0.5)
                tileNode.position.y -= (tileSize.height * 0.5)

                tileNode.physicsBody = SKPhysicsBody(rectangleOf: tileSize, center: tileNode.position)
                tileNode.physicsBody?.isDynamic = false
                tileNode.physicsBody?.collisionBitMask = playerCategory|groundCategory

                //tileNode.physicsBody?.contactTestBitMask = playerCategory
                tileNode.physicsBody?.categoryBitMask = groundCategory
                landBackground.addChild(tileNode)
            }
        }
    }
SKPhysicsBody(矩形:波浪形,中心:波浪形位置)

这可能是不对的。电话文件上说:

所属节点坐标系中正方形的中心

这意味着您可能应该使用
.zero
。除非特别偏移,否则始终假定物理实体与其所属节点位于同一位置。决不应为此使用场景坐标


另外,请确保在
SKView
上将
showsPhysics
设置为
true
,以便查看它们的实际位置。

谢谢您解决了我的问题!