当我在游戏中给两个节点一个物理体时,他们就会停止做我想让他们做的事情。我在场景底部有两个酒吧,一个在左边开始,另一个在右边,他们不断地在中间相遇,然后回到那里的起点,就像一个地板开放。如果没有物理身体,他们就是这样做的,但是当我给他们一个物理身体时,当他们在中间相遇时,他们会停在那里而不会退回去。
以下是条形图:
bar.position = CGPoint(x:-self.size.width * 0.2, y:(self.size.height * 0.03));
bar.physicsBody = SKPhysicsBody(texture: text, size: text.size())
bar.physicsBody?.categoryBitMask = PhysicsCategory.bar
bar.physicsBody?.contactTestBitMask = PhysicsCategory.ball
bar.physicsBody?.collisionBitMask = PhysicsCategory.bar
self.addChild(bar)
bar1.position = CGPoint(x:self.size.width * 1.2, y:(self.size.height * 0.03));
bar1.physicsBody = SKPhysicsBody(texture: text, size: text.size())
bar1.physicsBody?.categoryBitMask = PhysicsCategory.bar
bar1.physicsBody?.contactTestBitMask = PhysicsCategory.ball
bar1.physicsBody?.collisionBitMask = PhysicsCategory.bar
self.addChild(bar1)
这就是他们的举动。这是在更新方法中:
if (bar.position.x == -self.size.width * 0.2)
{
let move = SKAction.moveToX(self.size.width * 0.012, duration: 1);
bar.runAction(move);
} else if (bar.position.x == self.size.width * 0.012) {
let move = SKAction.moveToX(-self.size.width * 0.2, duration: 1)
bar.runAction(move)
}
if (bar1.position.x == self.size.width * 1.2)
{
let move = SKAction.moveToX(self.size.width * 0.988, duration: 1);
bar1.runAction(move);
} else if (bar1.position.x == self.size.width * 0.988) {
let move = SKAction.moveToX(self.size.width * 1.2, duration: 1)
bar1.runAction(move)
}
当我给他们一个物理身体时,什么可能导致他们在中间粘在一起。