我有一个奇怪的行为SKPhysicsbody
。
首先让我向您展示我的主节点:
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"
现在最重要的是,还有另一个没有任何物理体的 SKSpriteNode,我们称之为path
。
一段时间后,我生成了另一个节点,即上面的 playernode 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
所以在我看来,只有当它被移到节点之外并且它真的触及背景didBeginContact
时才应该触发。playerNode
path
但目前,在didBeginContact
我将 playerNode 生成在path
.
我错过了什么吗?