我有一个碰撞检测,它工作正常,问题是,每当我bird
的“”击中“ cloud
”,云消散,我得到一些分数。应该发生的“ sol
”也是如此,但云却没有。
这怎么能改变?我尝试了很多,但似乎可以解决。
碰撞代码
- (void)update:(ccTime)dt {
bird.position = ccpAdd(bird.position, skyVelocity);
NSMutableArray *projectilesToDelete = [[NSMutableArray alloc] init];
for (CCSprite *bird in _projectiles) {
bird.anchorPoint = ccp(0, 0);
CGRect absoluteBox = CGRectMake(bird.position.x, bird.position.y, [bird boundingBox].size.width, [bird boundingBox].size.height);
NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init];
for (CCSprite *cloudSprite in _targets) {
cloudSprite.anchorPoint = ccp(0, 0);
CGRect absoluteBox = CGRectMake(cloudSprite.position.x, cloudSprite.position.y, [cloudSprite boundingBox].size.width, [cloudSprite boundingBox].size.height);
if (CGRectIntersectsRect([bird boundingBox], [cloudSprite boundingBox])) {
[targetsToDelete addObject:cloudSprite];
}
}
for (CCSprite *solSprite in _targets) {
solSprite.anchorPoint = ccp(0, 0);
CGRect absoluteBox = CGRectMake(solSprite.position.x, solSprite.position.y, [solSprite boundingBox].size.width, [solSprite boundingBox].size.height);
if (CGRectIntersectsRect([bird boundingBox], [solSprite boundingBox])) {
[targetsToDelete addObject:solSprite];
score += 50/2;
[scoreLabel setString:[NSString stringWithFormat:@"%d", score]];
}
}
// NÅR SKYEN BLIVER RAMT AF FUGLEN
for (CCSprite *cloudSprite in targetsToDelete) {
//[_targets removeObject:cloudSprite];
//[self removeChild:cloudSprite cleanup:YES];
}
// NÅR SOLEN BLIVER RAMT AF FUGLEN
for (CCSprite *solSprite in targetsToDelete) {
[_targets removeObject:solSprite];
[self removeChild:solSprite cleanup:YES];
}
if (targetsToDelete.count > 0) {
[projectilesToDelete addObject:bird];
}
[targetsToDelete release];
}
// NÅR FUGLEN BLIVER RAMT AF ALT ANDET
for (CCSprite *bird in projectilesToDelete) {
//[_projectiles removeObject:bird];
//[self removeChild:bird cleanup:YES];
}
[projectilesToDelete release];
}