Crashalot Crashalot - 6 months ago 43
Swift Question

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

In the

function below, one of the nodes has a category bit mask of 4294967295. However, this category is never assigned to any node.

Here are all the bit masks in use:

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

To repeat, the
category, which corresponds to 4294967295, is never assigned to any node. So why is there a physics body with this category bit mask? Is this category bit mask ever implicitly assigned to a physics body?

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


categoryBitMask is a UInt32 and its max value is 4294967295 which is also its default value (all bits set). Quote from 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).