问题
I have the following code, the didBeginContact(contact:)
method is called but not didEndContact(contact:)
.
// FIXME: This is a workaround until class vars are supported
let sharedContactHandler = ContactHandler()
class ContactHandler: NSObject, SKPhysicsContactDelegate {
class var sharedHandler: ContactHandler {
get {
return sharedContactHandler
}
}
func didBeginContact(contact: SKPhysicsContact) {
let bodyA = contact.bodyA
let bodyB = contact.bodyB
NSLog("Began contact")
...
}
func didEndContact(contact: SKPhysicsContact) {
let bodyA = contact.bodyA
let bodyB = contact.bodyB
NSLog("Ended contact")
...
}
...
}
And in my scene,
physicsWorld.contactDelegate = ContactHandler.sharedHandler
I've searched around and can't find any reason why one should be called but not the other. I've made sure that the method signatures are correct and everything.
When two bodies come into contact, I see "Began contact" in the log but once they are no longer in contact, "Ended contact" never appears.
Any ideas on what I'm doing wrong?
来源:https://stackoverflow.com/questions/29331799/spritekit-didbegincontact-called-but-not-didendcontact