私は衝突検出を持っていて、それはうまく機能しています、問題は、私の「」が「bird
」に当たるときはいつでもcloud
、雲が消えて、私がいくつかのポイントを得るということです。同じことが「sol
」にも起こりますが、雲には起こりません。
これはどのように変更できますか?iveはたくさん試しましたが、それを理解しているように見えます。
衝突コード
- (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];
}