I am attempting to do some collision detection between sprites and am quite simply not getting results.
I have [self checkForCollision] in my update method, and this is my checkForCollision method:
-(void) checkForCollision
{
// Assumption: both player and spider images are squares
float playerImageSize = [player texture].contentSize.width;
float spiderImageSize = [[spiders lastObject] texture].contentSize.width;
float playerCollisionRadius = playerImageSize * 0.4f;
float spidercollisionRadius = spiderImageSize * 0.4f;
// This collision distance will roughly equalt the image shapes
float maxCollisionDistance = playerCollisionRadius + spidercollisionRadius;
int numSpiders = [spiders count];
for (int i = 0; i < numSpiders; i++)
{
CCSprite* spider = [spiders objectAtIndex:i];
if ([spider numberOfRunningActions] == 0)
{
continue;
}
// get the distance between the player and the spider
float actualDistance = ccpDistance(player.position, spider.position);
// are the two objects closer than allowed?
if (actualDistance < maxCollisionDistance)
{
// no game over just reset the spiders
[self resetSpiders];
}
}
}
It seems my spider sprites just fly through my player sprite, without any result.
Any suggestions would be greatly welcomed.