【发布时间】:2012-02-25 22:30:36
【问题描述】:
大家好,我在碰撞检测方面遇到了问题。
我有第一个添加随机对象的方法
-(void)initObjects{
int randomNumber = arc4random() % 5 + 1;
switch (randomNumber) {
case 1:
[self initEnemy];
CCLOG(@"Random number 1");
break;
case 2:
[self initJetpack];
break;
case 3:
[self initWine];
break;
case 4:
// [self initNight];
break;
default:
CCLOG(@"no number");
break;
}
}
那么什么时候选择生成对象的方法,如果碰撞检测删除添加的精灵
每个对象方法的代码
[self schedule:@selector(collision) interval:1 / 60];
碰撞方式:
-(void)collision {
if (CGRectIntersectsRect([_hero boundingBox], [_enemy boundingBox])) {
CCLOG(@"Enemy collision intercect");
[self spriteMoveFinished:_enemy]; // It's method like [self removeChild:_enemy cleanup:YES];
[self unschedule:@selector(collision)];
} else if (CGRectIntersectsRect([_hero boundingBox], [_powerNight boundingBox])) {
CCLOG(@"PowerNight collision intercect");
// the same up
} else if (CGRectIntersectsRect([_hero boundingBox], [_wine boundingBox])) {
CCLOG(@"Wine collision intercect");
// the same up
} else if (CGRectIntersectsRect([_hero boundingBox], [_jetPack boundingBox])) {
CCLOG(@"Jetpack collision intercect");
//the same up
}
}
现在是有趣的日志
JetPack 已初始化 酒碰撞拦截(?????????) 为什么酒??
敌人初始化 Jetpack 碰撞拦截 (????? ) 为什么是 jetPack??
但有时还可以
敌人初始化 敌人碰撞拦截
我哪里错了?
谢谢大家的欢呼
【问题讨论】:
标签: cocos2d-iphone collision-detection collision