Reputation: 401
scorenode = SKSpriteNode()
scorenode.size = CGSize(width: self.frame.width * 0.2, height: 1)
scorenode.physicsBody = SKPhysicsBody(rectangleOf: scorenode.size)
scorenode.color = .red
scorenode.physicsBody?.affectedByGravity = false
scorenode.physicsBody?.isDynamic = false
scorenode.physicsBody?.categoryBitMask = PhysicsCategory.score
scorenode.physicsBody?.contactTestBitMask = PhysicsCategory.circle
scorenode.physicsBody?.collisionBitMask = 0
obstaclePair = SKNode()
obstaclePair.name = "obstaclePair"
rightObstacle = SKSpriteNode(imageNamed:"square")
rightObstacle.size = CGSize(width: self.frame.width * 0.8, height: self.frame.height / 10)
rightObstacle.color = oColor
rightObstacle.colorBlendFactor = 1.0
rightObstacle.physicsBody = SKPhysicsBody(rectangleOf: rightObstacle.size)
rightObstacle.physicsBody?.categoryBitMask = PhysicsCategory.obstacle
rightObstacle.physicsBody?.collisionBitMask = PhysicsCategory.circle
rightObstacle.physicsBody?.contactTestBitMask = PhysicsCategory.circle
rightObstacle.physicsBody?.isDynamic = false
leftObstacle = SKSpriteNode(imageNamed:"square")
leftObstacle.size = CGSize(width: self.frame.width * 0.8 , height: self.frame.height / 10)
leftObstacle.physicsBody = SKPhysicsBody(rectangleOf: leftObstacle.size)
leftObstacle.color = oColor
leftObstacle.colorBlendFactor = 1.0
leftObstacle.physicsBody?.categoryBitMask = PhysicsCategory.obstacle
leftObstacle.physicsBody?.collisionBitMask = PhysicsCategory.circle
leftObstacle.physicsBody?.contactTestBitMask = PhysicsCategory.circle
leftObstacle.physicsBody?.isDynamic = false
circle = SKSpriteNode(imageNamed: "Circle")
circle.size = CGSize(width: 50, height: 50)
circle.position = CGPoint(x: self.frame.width / 2, y: self .frame.height / 4)
circle.color = .blue
circle.colorBlendFactor = 1.0
circle.physicsBody = SKPhysicsBody(circleOfRadius: circle.frame.height / 2)
circle.physicsBody?.categoryBitMask = PhysicsCategory.circle
circle.physicsBody?.collisionBitMask = PhysicsCategory.obstacle
circle.physicsBody?.contactTestBitMask = PhysicsCategory.obstacle | PhysicsCategory.score
circle.physicsBody?.affectedByGravity = false
circle.physicsBody?.isDynamic = true
circle.zPosition = 10
This is the physics part of my project, and I have a Circle SKSpritenode and a score node SKSpritenode. They aren't supposed to collide and i didn't put a collision bit mask for them both, but they still collide. What am i doing wrong?
Upvotes: 3
Views: 208
Reputation: 128
you have
static let circle : UInt32 = 0x1 << 1
static let obstacle : UInt32 = 0x1 << 1
static let score : UInt32 = 0x1 << 1
you need
static let circle : UInt32 = 0x1 << 0
static let obstacle : UInt32 = 0x1 << 1
static let score : UInt32 = 0x1 << 2
Upvotes: 2
Reputation: 105
If you're not doing anything physics related with the score node why not just make it a labelnode and remove the physics from it.
Upvotes: 0