有两个物理体:一个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
属性,则会触发。YES
AirplaneNode
BulletNode
didBeginContact
有没有办法解决这个问题?
PS:我真的不需要我的节点是动态的,因为它会导致不必要的行为:飞机受损时会轻微移动,而子弹有时会在飞行时旋转。