Created
August 2, 2012 19:58
-
-
Save krzysztofzablocki/3240133 to your computer and use it in GitHub Desktop.
Handling dial like rotation on CCNode by using UIPanGestureRecognizer
This file contains hidden or 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
//! for gesture recognizer support in cocos2d use https://github.com/krzysztofzablocki/CCNode-SFGestureRecognizers | |
- (void)handlePanGesture:(UIPanGestureRecognizer*)gestureRecognizer | |
{ | |
CGPoint location = [[CCDirector sharedDirector] convertToGL:[gestureRecognizer locationInView:gestureRecognizer.view]]; | |
static CGPoint oldLocation; | |
//! this will make sure that oldLocation is initialized | |
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) { | |
//! we need to calculate angle difference between previous position and current one in regards to dial center | |
CGPoint firstDir = ccpSub(oldLocation, dial.position); | |
CGPoint secondDir = ccpSub(location, dial.position); | |
prevAngle = -ccpToAngle(firstDir); | |
curAngle = -ccpToAngle(secondDir); | |
angleChange = CC_RADIANS_TO_DEGREES(curAngle - prevAngle); | |
dial.rotation += angleChange; | |
} | |
oldLocation = location; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment