SpriteKit didBeginContact called but not didEndContact

这一生的挚爱 提交于 2019-12-11 02:48:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!