所以我在我的GameScene
班级中有这段代码(的孩子SKScene
):
physicsWorld.contactDelegate = self
physicsWorld.gravity = CGVector(dx: 0, dy: -9.8)
addChild(balloon)
addChild(monkey)
monkey.physicsBody = SKPhysicsBody(rectangleOf: monkey.frame.size)
monkey.physicsBody?.isDynamic = false
monkey.physicsBody?.categoryBitMask = 0
monkey.physicsBody?.contactTestBitMask = 1//Balloon.categoryBitMask
balloon.physicsBody = SKPhysicsBody(rectangleOf: balloon.frame.size)
balloon.physicsBody?.isDynamic = false
balloon.physicsBody?.categoryBitMask = 1
balloon.physicsBody?.contactTestBitMask = 0
balloon.start()
我可以看到气球和猴子节点在模拟器中已经相互接触,但是没有任何反应。我也遵守了SKPhysicsContactDelegate
协议,如下所示:
extension GameScene: SKPhysicsContactDelegate {
func didBegin(_ contact: SKPhysicsContact) {
print("CONTACT!!!")
}
}
编辑:我设置isDynamic = true
并打印“联系!!” 正如预期的那样,但是我不希望物体影响彼此的位置