In the past I mentioned some tutorials providing 2D collision detection techniques showing how to perform circle-to-rectangle, circle-to-circle (using UIKit), and vertex based collisions (with Cocos2D and Box 2D).
The most accurate collision method – pixel to pixel collisions – wasn’t mentioned simply because it can be brutally slow.
It is possible however to perform extremely fast pixel to pixel collisions using a pixel mask.
Steffen Itterheim has created a class known as KKPixelMaskSprite that inherits from CCSprite that automatically provides a pixel mask along with several methods for detecting collisions.
You can find the class along with an extensive tutorial on Steffen’s site here.
This looks like a terrific class for any Cocos2D developers wanting pixel accurate collisions at a decent speed. The speed of course can’t compare to vertex based collisions with only a few vertices, but if you really want pixel perfect collisions this loks like the way to go.
©2011 iPhone, iOS 5, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.
.