在下面的 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/