1
私はSKTileMapNodeとSKTileMapsを使用してサイドコントロールを作成しようとしていますが、個々のタイルのフィジックスボディに問題があります。SKTileMapNode衝突が動作しない
https://forums.developer.apple.com/thread/50043
私のプレーヤーのノードが地面を通過しかし:このリンクで説明したように、私は、ループ内でそれらを作成します。私は間違って何をしていますか?
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)
}
}
}
ありがとうございましたこれが私の問題を修正しました! –