7

有两个物理体:一个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方法。但是,如果我为or指定physicsBody.dynamic属性,则会触发。YESAirplaneNodeBulletNodedidBeginContact

有没有办法解决这个问题?

PS:我真的不需要我的节点是动态的,因为它会导致不必要的行为:飞机受损时会轻微移动,而子弹有时会在飞行时旋转。

4

1 回答 1

17

非动态(静态)物体永远不会发生碰撞,它们一开始并不意味着改变它们的位置。

collisionBitMask如果您不希望它们受到碰撞的影响,请将它们设置为 0。请参阅SKPhysicsBody 参考资料

于 2013-11-01T10:11:08.550 回答