我已经创建了2个节点但是当它们没有接触时,这里是代码:
private var circle:Circle?
circle?.name = "Ball"
circle?.physicsBody?.isDynamic = true
circle?.physicsBody?.categoryBitMask = 1
circle?.physicsBody!.contactTestBitMask = 2
self.addChild(Circle(radius: 100 , position: location ))
let obstacle = SKSpriteNode(color: UIColor.white, size : CGSize(width: 0, height : 30))
obstacle.name = "OBSTACLE"
obstacle.physicsBody?.isDynamic = true
obstacle.position = CGPoint( x : 0 ,y : self.size.height + obstacle.size.height )
obstacle.physicsBody = SKPhysicsBody.init(rectangleOf: obstacle.size)
obstacle.physicsBody?.isDynamic = true
obstacle.physicsBody?.categoryBitMask = 2
self.addChild(obstacle)
func didBegin(_ contact: SKPhysicsContact) {
if contact.bodyA.node?.name == "Ball" {
print(" something ")
}
}
这两个节点是在视图中实现的,但是当他们联系时我没有得到“东西”。
我不知道接触测试位掩码有什么问题。