有两个物理机构:AirplaneNode:
- (id)initAirplaneNode { self = [super initWithImageNamed:@"airplane.png"]; if (self) { self.name = @"player"; self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size]; self.physicsBody.dynamic = NO; self.physicsBody.affectedByGravity = NO; self.physicsBody.categoryBitMask = AIRPLANE_CATEGORY; self.physicsBody.contactTestBitMask = BULLET_CATEGORY; } return self; }
和一个BulletNode:
- (id)initBulletNode { self = [super initWithImageNamed:@"bullet.png"]; if (self) { self.name = @"bullet"; self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size]; self.physicsBody.dynamic = NO; self.physicsBody.usesPreciseCollisionDetection = YES; self.physicsBody.categoryBitMask = BULLET_CATEGORY; self.physicsBody.contactTestBitMask = AIRPLANE_CATEGORY; } return self; }
它们都将physicsBody.dynamic属性设置为NO.
问题是当子弹击中飞机时,我的SKScene不会调用didBeginContact方法.但是,如果我为PlaneplaneNode或BulletNode指定physicsBody.dynamic属性为YES,则didBeginContact将被触发.
有办法解决这个问题吗?
PS:我真的不需要我的节点是动态的,因为它会导致不必要的行为:飞机在受到损坏时轻微移动,子弹在飞行时有时会旋转.
解决方法
非动态(静态)物体永远不会发生碰撞,它们并不意味着首先改变它们的位置.
如果您不希望它们受到冲突的影响,请将其collisionBitMask设置为0.请参阅SKPhysicsBody reference.