问题
func didBeginContact(contact: SKPhysicsContact) {
if contact.bodyA.categoryBitMask == PhysicsCategory.overPow || contact.bodyB.categoryBitMask == PhysicsCategory.overPow{
let sk = delegateForCollision!.view as! SKView
let newScene = GG(fileNamed: "GG")
newScene!.delegateFor = delegateForCollision
newScene?.scaleMode = .AspectFill
sk.presentScene(newScene)
}
if contact.bodyA.categoryBitMask == PhysicsCategory.glem && contact.bodyB.categoryBitMask == PhysicsCategory.kappa{
contact.bodyA.node?.removeFromParent()
glem++
glemLabel.text = "SKAŁY: \(glem)"
}
if contact.bodyB.categoryBitMask == PhysicsCategory.glem && contact.bodyA.categoryBitMask == PhysicsCategory.kappa{
contact.bodyB.node?.removeFromParent()
glem++
glemLabel.text = "SKAŁY: \(glem)"
}
}
glem
and kappa
categoryBitMask
nodes are colliding so glem
variable should be ++ one time then node is removed from scene but it looks like this method is called more times during next frames. I see it in logs because I added print("\(glem)")
in glem didSet. Why does it happen?
回答1:
I changed glem++
to if contact.bodyB.node?.parent != nil{glem++}
and now it works as it should.
来源:https://stackoverflow.com/questions/34188183/why-my-node-calls-didbegincontact-method-when-its-not-in-the-scene