0

我已经创建了 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  ")
        }
      }

这两个节点被实现到视图中,但是当他们联系时我没有得到“某物”。

我不知道接触测试位掩码有什么问题。

4

0 回答 0