我需要帮助来销毁精灵,这是在碰撞的精灵和周围的半径2.5厘米,所有的精灵都应该被销毁。这里的想法是,我将从底部向从顶部落下的物体发射一枚射弹。一旦发生碰撞,该半径周围的所有精灵也应该被销毁。就像炸弹效应。我已经使用了box2d的冲突,即联系侦听器。那该怎么做呢?
请建议:-)
致以敬意,
卡尔蒂克
发布于 2010-12-14 19:16:41
保存您的精灵数组,或者如果您使用的是batchNode,则可以这样做。
当碰撞发生时,通过你的精灵。检查他们的位置和爆炸中心的距离,如果他们在射程内就杀死他们。
例如:
CCSprite *sprite;
for (sprite in [batchNode descendants]) {
if ([sprite isInRangeOf:[explosionSprite position]]) {
[sprite yourRemovalMethod];
}
}方法'isInRangeOf:‘将在您的sprite子类中
就像..。
-(BOOL) isInRangeOf:(CGPoint)explosionCenter {
//Use pythagoras theorem to work out the distance between [sprite position] and [explosionCenter]
CGFloat dx = explosionCenter.x - [self position].x;
CGFloat dy = explosionCenter.y - [self position].y;
float distance = sqrt(dx*dx + dy*dy );
// If your distance is less than or equal to your 'death radius' return YES, else No.
if (distance <= 25) {
return TRUE;
} else {
return FALSE;
}
}希望这能有所帮助。
https://stackoverflow.com/questions/4436333
复制相似问题