Last active
August 29, 2015 14:00
-
-
Save maxchuquimia/11306381 to your computer and use it in GitHub Desktop.
Cocos2D/Box2D/LevelHelper Manual Collision Detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Put this in a subclass of LHSprite! | |
* Then, in your layer's update: method you can check if a sprite is touching another sprite: | |
* [mySpriteClassInstance isCollidedWithSprite:anotherSprite]; | |
*/ | |
- (BOOL)isCollidedWithSprite:(LHSprite *)spriteB | |
{ | |
BOOL isTouching = FALSE; | |
for (b2Fixture *fA = self.body->GetFixtureList(); fA; fA = fA->GetNext()) | |
{ | |
b2Shape *shapeA = fA->GetShape(); | |
for (b2Fixture *fB = spriteB.body->GetFixtureList(); fB; fB = fB->GetNext()) | |
{ | |
b2Shape *shapeB = fB->GetShape(); | |
if (b2TestOverlap(shapeA, 0, shapeB, 0, self.body->GetTransform(), spriteB.body->GetTransform())) | |
{ | |
isTouching = TRUE; | |
break; | |
} | |
} | |
if (isTouching) | |
{ | |
break; | |
} | |
} | |
return isTouching; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment