标签: skphysicscontact

didBeginContact传递了PKPhyicsObject

我有一个扩展的帮助方法 SKPhysicsContact

extension SKPhysicsContact {

    /// - returns: `[SKPhysicsBody]` containing all the bodies that match `mask`
    func bodiesMatchingCategory(mask: UInt32) -> [SKPhysicsBody] {
        let bodies = [bodyA, bodyB]
        return bodies.filter { ($0.categoryBitMask & mask) != 0 }
    }
}
Run Code Online (Sandbox Code Playgroud)

didBeginContact()我呼吁在过了这个方法contact.

func didBeginContact(contact: SKPhysicsContact) {
    let ballMask: UInt32 = 0x1 << 2
    let ball = contact.bodiesMatchingCategory(ballMask)
...
Run Code Online (Sandbox Code Playgroud)

我有时会收到此错误消息(如5中的1),这会导致应用程序崩溃:

-[PKPhysicsContact bodiesMatchingCategory:]: unrecognized selector sent to instance 0x165f2350
Run Code Online (Sandbox Code Playgroud)

我查了一下PKPhysicsContact,它是私人框架(链接)的一部分. SKPhysicsContact看起来它只是一个空的类定义,它只暴露了某些属性PKPhysicsContact.

我觉得这是SpriteKit团队的一个Objective-C黑客攻击,打破了Swift强大的打字.

救命?

如何确保我总是 …

interop ios sprite-kit skphysicscontact swift

5
推荐指数
1
解决办法
125
查看次数

标签 统计

interop ×1

ios ×1

skphysicscontact ×1

sprite-kit ×1

swift ×1