SpriteKit冲突检测无法正常工作

时间:2019-03-05 17:26:59

标签: swift skphysicsbody skphysicscontact

因此我的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,并打印了“ CONTACT !!”。符合预期,但是我不希望这些对象影响彼此的位置

0 个答案:

没有答案