0

我有一个收集陨石的基本火箭游戏。很基础。游戏运行良好,除了有一个真正的烦恼,我一直试图解决但不能。

当火箭与陨石相撞时:

-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair rocket:(CCNode *)nodeA meteorite:(CCNode *)nodeB{
[self meteoriteRemoved:nodeB];
[self spawnMeteorite];
score ++;
_scoreLabel.string = [NSString stringWithFormat:@"%d", score];
}

它被移除并重生。这很好用,但是如果陨石靠近另一颗陨石并且火箭猛烈撞击其中一颗,它会像斯诺克球一样将另一颗撞到一边。我希望它们保持静止,直到火箭与它们相撞。

有什么方法可以告诉同一个碰撞组中的精灵互相忽略吗?

编辑**

我正在从一个类循环加载陨石,该类具有:

@implementation Meteorite

- (void)didLoadFromCCB {
self.physicsBody.collisionType = @"meteorite";
}

@结尾

然后使用以下方法生成它们:

-(void)spawnMeteorite{
CCNode *meteorite = [CCBReader load:@"Meteorite"];

CGFloat randomX = ((double)arc4random() / ARC4RANDOM_MAX);
CGFloat randomY = ((double)arc4random() / ARC4RANDOM_MAX);
CGFloat rangeX = 320 - 48;
CGFloat rangeY = 2880 - 200;

meteorite.position = ccp((randomX * rangeX)+24, (randomY * rangeY)+ _ground.contentSize.height + _rocket.contentSize.height);
meteorite.physicsBody.velocity = ccp(0,0);
[_physicsNode addChild:meteorite];

}

The following code gives a log of Meteorite Hit extremely often when flying into a group, and most of them fly off into oblivion!

-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair meteorite:(CCNode *)nodeA meteorite:(CCNode *)nodeB{
NSLog(@"Meteorite HIT");
}

Thanks for looking into this, hope it helps

4

1 回答 1

1

Objects with the same collision group do not collide with each other. The documentation states:

/**
 *  The body's collisionGroup, if two physics bodies share the same group id, they don't collide. Defaults to nil.
 */
@property(nonatomic, assign) id collisionGroup;

Could you share the code that assigns the collision group to your physics objects? You need to be careful here, because the "same" collision group means the exact same pointer to the same object!

于 2014-05-27T23:32:02.890 回答