Skip to content

Instantly share code, notes, and snippets.

@whitmanc
Created August 15, 2012 13:37
Show Gist options
  • Save whitmanc/3360240 to your computer and use it in GitHub Desktop.
Save whitmanc/3360240 to your computer and use it in GitHub Desktop.
Cocos2d-iphone prevent physics objects overlap
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchPoint = [touch locationInView:[touch view]];
touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];
if(isTouch){
//
// Move the flake, check into consideration finger placement
// relative to the flake
//
CGPoint point = [self convertTouchToNodeSpace:touch];
cpShape *shape = [smgr getShapeAt:point];
if (shape && [shape->body->data class] != [cpCCSprite class]) {
touchedFlake.shape->body->p=ccpSub(touchPoint, difTouch);
}
if (shape && [shape->body->data class] == [cpCCSprite class]) {
[smgr morphShapeToActive:touchedFlake.shape mass:1];
return;
}
if (shape == NULL) {
touchedFlake.shape->body->p=ccpSub(touchPoint, difTouch);
}
[smgr rehashShape:touchedFlake.shape];
lastMovePoint = touchPoint;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment