我有一个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
}
}
}
答案 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
}
}