I am trying to detect collisions in cocos2D. I am using this code:
- (void)checkForCollisionSpeedUp:(ccTime)dt
{
CGRect projectileRect = CGRectMake(
guy.position.x,
guy.position.y,
2,
20);
CGRect targetRect = CGRectMake(
speedUp.position.x - (speedUp.contentSize.width/2),
speedUp.position.y - (speedUp.contentSize.height/2),
speedUp.contentSize.width,
speedUp.contentSize.height);
if (CGRectIntersectsRect(projectileRect, targetRect)) {
[[SimpleAudioEngine sharedEngine] playEffect:@"Robot_blip-Marianne_Gagnon-120342607.wav"];
[bg removeChild:speedUp cleanup:YES];
}
}
That code detects the collision, it plays the sound, and removes the sprite, but not the CGRect. The CGRect remains in the position of the sprite when it was deleted. How do I solve this?
Thanks,
Tate
Also, I really don't want to use Box2D or Chipmunk for collision detection.