在联系之后尝试隐藏节点

时间:2015-02-09 20:04:10

标签: iphone swift ios8 sprite-kit

我有一个SKSprite节点,我希望在联系完成后消失。我试图设置.hidden = true但是这不起作用

var coin = SKSpriteNode()
//MARK: SKPhysicsContactDelegate methods

func didBeginContact(contact: SKPhysicsContact) {

    if (contact.bodyA.categoryBitMask == userCategory) && (contact.bodyB.categoryBitMask == objectCategory) {

        gameOver = 1
        movingObjects.speed = 0
        presentGameOverView()

    } else if (contact.bodyA.categoryBitMask == userCategory) && (contact.bodyB.categoryBitMask == coinCategory) {

        println("scoring")
        //code to hide node
        coin.hidden = true //not working

    }
}

}

1 个答案:

答案 0 :(得分:1)

SKPhysicsBody有一个名为node的属性。这可以在didContactBegin函数中访问,以隐藏node

func didBeginContact(contact: SKPhysicsContact) {

    if (contact.bodyA.categoryBitMask == userCategory) && (contact.bodyB.categoryBitMask == coinCategory) {

        println("scoring")
        //code to hide node
        contact.bodyB.node?.hidden = true // Changed

    }
}