SpriteKit:当此类别从未分配给节点时,为什么碰撞中的节点具有类别位掩码 4294967295
SpriteKit: why node in collision has category bit mask of 4294967295 when this category was never assigned to a node
在下面的 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
}
重复一下,对应于 4294967295 的 All
类别从未分配给任何节点。那么为什么会有这个类别位掩码的物理体呢?此类别位掩码是否曾经隐式分配给物理体?
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).
在下面的 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
}
重复一下,对应于 4294967295 的 All
类别从未分配给任何节点。那么为什么会有这个类别位掩码的物理体呢?此类别位掩码是否曾经隐式分配给物理体?
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).