I am trying to create walls in Swift using an SKShapenode. Even with the collision bit mask set to 'All', the characters still move through the rectangle and don't interact with it.
Set up physics categories:
struct PhysicsCategory {
static let None : UInt32 = 0
static let All : UInt32 = UInt32.max
static let Monster : UInt32 = 0b1
static let Projectile: UInt32 = 0b10
static let Walls : UInt32 = 0b11
static let Player : UInt32 = 0b100
}
How I tried to set up the walls:
let rectangle = SKShapeNode(rectOfSize: CGSize(width:390, height:200))
rectangle.position = CGPointMake(frame.midX-10, frame.midY + 50)
rectangle.strokeColor = SKColor.blackColor()
rectangle.glowWidth = 1.0
rectangle.physicsBody = SKPhysicsBody(edgeLoopFromRect: rectangle.frame)
rectangle.physicsBody?.dynamic = false
rectangle.physicsBody?.categoryBitMask = PhysicsCategory.Walls
rectangle.physicsBody?.contactTestBitMask = PhysicsCategory.None
rectangle.physicsBody?.collisionBitMask = PhysicsCategory.All
self.addChild(rectangle)