更新到 Swift 2.0 后,这不再有效:
if contact.bodyA != nil && contact.bodyB != nil {
返回:
Binary operator '&&' cannot be applied to two Bool operands
我尝试使用嵌套 if 语句分别对每个主体进行 nil 检查,似乎您无法再对物理主体进行 nil 检查...
想法?
最佳答案
从 iOS9 开始,bodyA
和 bodyB
不再是可选的:
class SKPhysicsContact : NSObject {
var bodyA: SKPhysicsBody { get }
var bodyB: SKPhysicsBody { get }
// ...
}
因此你无法检查它们是否nil
。要解决您的问题,只需使用 bodyA
和 bodyB
,就像任何其他非可选的一样。
关于Swift 2.0 SKPhysicsBody nil 检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31248352/