I've got a strange behavior of SKPhysicsbody
.
First let me show you my main-node:
self.physicsWorld.contactDelegate = self
self.physicsWorld.gravity = CGVectorMake(0, 0)
self.physicsBody = SKPhysicsBody(rectangleOfSize: self.frame.size)
self.physicsBody!.collisionBitMask = player
self.physicsBody!.categoryBitMask = wall
self.physicsBody!.contactTestBitMask = player
self.physicsBody?.dynamic = true
self.name = "background"
Now on top of that, there is another SKSpriteNode without any physicsbody, let's call it path
.
After some time, I spawn another node, the playernode on top of that path
:
playerNode = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(tileSize/1, tileSize/1))
playerNode.position = CGPointMake(self.frame.width/2, self.frame.height/2)
playerNode.zPosition = 3
playerNode.name = "player"
playerNode.physicsBody = SKPhysicsBody(rectangleOfSize: playerNode.size)
playerNode.physicsBody!.categoryBitMask = player
playerNode.physicsBody!.collisionBitMask = wall
playerNode.physicsBody!.contactTestBitMask = wall
playerNode.physicsBody?.dynamic = false
So in my opinion, the didBeginContact
should trigger only if the playerNode
is moved outside of the path
node and if it really touches the background.
But at the moment, the didBeginContact
triggers immediately after I spawn my playerNode on top of my path
.
Am I missing something?