Created
April 8, 2013 10:51
-
-
Save aliHafizji/5335918 to your computer and use it in GitHub Desktop.
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
- (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