Collision with CCSprite
- by Coder404
I'm making an iOS app based off the code from here
In the .m file of the tutorial is this:
-(void)update:(ccTime)dt {
  NSMutableArray *projectilesToDelete = [[NSMutableArray alloc] init];
  for (CCSprite *projectile in _projectiles) {
CGRect projectileRect = CGRectMake(
  projectile.position.x - (projectile.contentSize.width/2), 
  projectile.position.y - (projectile.contentSize.height/2), 
  projectile.contentSize.width, 
  projectile.contentSize.height);
NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init];
for (CCSprite *target in _targets) {
  CGRect targetRect = CGRectMake(
    target.position.x - (target.contentSize.width/2), 
    target.position.y - (target.contentSize.height/2), 
    target.contentSize.width, 
    target.contentSize.height);
  if (CGRectIntersectsRect(projectileRect, targetRect)) {
    [targetsToDelete addObject:target];             
  }                     
}
for (CCSprite *target in targetsToDelete) {
  [_targets removeObject:target];
  [self removeChild:target cleanup:YES];                                    
}
if (targetsToDelete.count > 0) {
  [projectilesToDelete addObject:projectile];
}
[targetsToDelete release];
  }
  for (CCSprite *projectile in projectilesToDelete) {
[_projectiles removeObject:projectile];
[self removeChild:projectile cleanup:YES];
  }
  [projectilesToDelete release];
}
I am trying to take away the projectiles and have the app know when the CCSprite "Player" and the targets collide. Could someone help me with this?
Thanks