Reputation: 607
I have a SKSprite node that I want to make disappear after contact was made. I tried to set the .hidden = true but this did not work
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
}
}
}
Upvotes: 0
Views: 45
Reputation: 24572
The SKPhysicsBody
has a property called node
. This can be accessed inside the didContactBegin
function to hide the 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
}
}
Upvotes: 1