ios – 如果physicsBody.dynamic属性为NO,则两个物理实体不联系

前端之家收集整理的这篇文章主要介绍了ios – 如果physicsBody.dynamic属性为NO,则两个物理实体不联系前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有两个物理机构: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.

原文链接:https://www.f2er.com/iOS/331215.html

猜你在找的iOS相关文章