在我的游戏中,我有不同颜色的圆圈。他们应该只与不属于他们颜色的边界发生碰撞。为此,我首先为正常圆分配一个类别位掩码。
struct CollisionCategoryBitmask {
static let monster: UInt32 = 00000001
static let picker: UInt32 = 00000010
static let bound: UInt32 = 00000100
static let circle: UInt32 = 00001000
static let yellow: UInt32 = 00010000
static let brown: UInt32 = 00100000
static let cyan: UInt32 = 01000000
static let magenta: UInt32 = 10000000
}
physicsBody?.categoryBitMask = CollisionCategoryBitmask.circle
边界具有以下掩码:
boundary.physicsBody?.categoryBitMask = CollisionCategoryBitmask.bound
boundary.physicsBody?.collisionBitMask = 11101111
在圆圈与选择器碰撞后,它会得到一个位掩码,应该使它停止与边界碰撞,但事实并非如此。
self.circles[i].fillColor = .yellow
self.circles[i].physicsBody?.categoryBitMask = 00010000
self.circles[i].physicsBody?.collisionBitMask = 11111011
当圆与选取器发生碰撞时,将执行此代码。结构中的值(如青色和洋红色)分别代表不与该颜色边界冲突的圆的状态。我的错误在哪里?