I follow the simple collision detection method of using the bounding box method, and checking whether they intersect.
The code is as follows:
CCRect projectileRect = projectileSprite->boundingBox();
CCRect enemyRect = enemySprite->boundingBox();
if (projectileRect.intersectsRect(enemyRect)) {
// do stuff
}
EDIT: I tried creating my own bounding box as well by getting the x, y positions and adding the width and height of the sprite.
Now, a funny thing happens is that is the collision detection works, but it works a bit incorrectly. The collision detection gets detected, before the actual intersection takes place.
I verified this by switching on CC_SPRITE_DEBUG_DRAW and it indeed takes place a few moments before the collision happens, i.e. the projectile's bounding box is outside the enemy's bounding box.
This seems to be a basic functionality that most folks recommend, and I seemed to be missing something. Can anyone deduce, what I could possibly be doing wrong?
PS: I verified this with cocos2d-x-2.2 and cocos2d-2.1rc0-x-2.1.3.
PPS: On a side note, I tried to draw my own bounding box using ccDrawSolidRect, but I can't seem to get that working.