Skip to content

Instantly share code, notes, and snippets.

@aliHafizji
Created April 8, 2013 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliHafizji/5335918 to your computer and use it in GitHub Desktop.
Save aliHafizji/5335918 to your computer and use it in GitHub Desktop.
- (void) rotateHandleWithTouch:(UITouch*)touch {
CGPoint previousLocation = [touch previousLocationInView:[touch view]];
CGPoint newLocation = [touch locationInView:[touch view]];
//preform all the same basic rig on both the current touch and previous touch
CGPoint previousGlLocation = [[CCDirector sharedDirector] convertToGL:previousLocation];
CGPoint newGlLocation = [[CCDirector sharedDirector] convertToGL:newLocation];
CCSprite *handle = (CCSprite*)[_spriteManager getChildByTag:HANDLE_TAG];
CGPoint previousVector = ccpSub(previousGlLocation, handle.position);
CGFloat firstRotateAngle = -ccpToAngle(previousVector);
CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);
CGPoint currentVector = ccpSub(newGlLocation, handle.position);
CGFloat rotateAngle = -ccpToAngle(currentVector);
CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
handle.rotation += (currentTouch - previousTouch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment