Skip to content

Instantly share code, notes, and snippets.

@haldun
Last active August 29, 2015 14:00
Show Gist options
  • Save haldun/048ea38c69dadcb1eec4 to your computer and use it in GitHub Desktop.
Save haldun/048ea38c69dadcb1eec4 to your computer and use it in GitHub Desktop.
move sprite by touch
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if (self.fingerIsOnWheel) {
CGPoint touchLocation = [touch locationInNode:self];
CGPoint previousLocation = [touch previousLocationInNode:self];
CGFloat angle1 = [self angleBetweenFirstPoint:previousLocation secondPoint:CGPointZero];
CGFloat angle2 = [self angleBetweenFirstPoint:touchLocation secondPoint:CGPointZero];
CGFloat bearingRadians = angle2 - angle1;
[self rotateBy:bearingRadians];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment