swift - SpriteKit : why node in collision has category bit mask of 4294967295 when this category was never assigned to a node

标签 swift sprite-kit skspritenode skphysicsbody

在下面的 didBegin 函数中,其中一个节点的类别位掩码为 4294967295。但是,此类别从未分配给任何节点。

这里是所有使用的位掩码:

struct PhysicsCategory {
    static let None                 : UInt32 = 0
    static let All                  : UInt32 = UInt32.max
    static let Player               : UInt32 = 0b1       // 1
    static let WorldBorder          : UInt32 = 0b10      // 2
    static let TopWorldBorder       : UInt32 = 0b100     // 4
    static let RightWorldBorder     : UInt32 = 0b1000    // 8
    static let Pellet               : UInt32 = 0b10000
}

重复一下,All 类别(对应于 4294967295)从未分配给任何节点。那么为什么会有这个类别位掩码的物理体呢?此类别位掩码是否曾经隐式分配给物理体?

func didBegin(_ contact: SKPhysicsContact) {
    print("Collision was detected: \(contact.bodyA.categoryBitMask). \(contact.bodyB.categoryBitMask).")
}

最佳答案

categoryBitMask 是一个 UInt32 并且它的最大值是 4294967295 这也是它的默认值(所有位设置)。引自 docs :

Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.

The default value is 0xFFFFFFFF (all bits set).

关于swift - SpriteKit : why node in collision has category bit mask of 4294967295 when this category was never assigned to a node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40858173/

相关文章:

ios - '.' 之后的 Swift/iOS/预期成员名称

ios - 在 Swift 函数之间传递索引值的最佳方式

ios - 如何将 UITableView 单元格设置为看起来像消息气泡?

ios - 如何实现键盘上方的按钮?

ios7 - 寻找子SKNode的绝对位置?

ios - 如何在swift中找到最接近场景底部的 Sprite 节点

ios - SKAction applyForce 不起作用?

sprite-kit - SpriteKit 局部纹理贴图

ios - 如何给 Sprite 准确的触摸位置?

swift - Sprite 套件中的接触检测