Game Development Reference
The image sizes of the player and spider are used as hints for the collision radii (or ra-
diuses, if you prefer). The approximation is good enough for this game. If you check
the DoodleDrop03 project, you'll also notice that I've added a debug drawing method
You're iterating over all the spiders but ignoring those that aren't moving at the mo-
ment because they'll definitely be out of range. The ccpDistance method calculates
the distance between the current spider and the player. This is another undocumented
but fully supported cocos2d method. You can find these and other useful math func-
tions in the CGPointExtension filesin the cocos2d/Support group in the
Xcode project and in the amended cocos2d API reference hosted on the Learn Co-
cos2D web site: www.learn-cocos2d.com/api-ref .
The resulting distance is then compared to the sum of the player's and spider's colli-
sion radius. If the actual distance is smaller than that, a collision has occurred. Because
you've not implemented a game-over, you can just reset all the spiders to restart the
// Iterate through all nodes of the layer.
for (CCNode* node in [self children])
// Make sure the node is a CCSprite and has the right tags.