Rotating a sprite to touch
- by user1691659
I know this has been asked before and Ive looked through peoples questions and answers all over the internet and I just cant get it to work.
Im sure its down to my inexperience. Ive got an arrow attached to a sprite, this sprite appears when touched but I want the arrow to point where the sprite will launch.
I have had the arrow moving but it was very erratic and not pointing as it should. Its not moving at the moment but this is what I have.
- (void)update:(ccTime)delta
{
arrow.rotation = dialRotation;
}
-(void) ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event
{
pt1 = [self convertTouchToNodeSpace:touch];
CGPoint firstVector = ccpSub(pt, arrow.position);
CGFloat firstRotateAngle = -ccpToAngle(firstVector);
CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);
CGPoint vector = ccpSub(pt1, arrow.position);
CGFloat rotateAngle = -ccpToAngle(vector);
CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
dialRotation += currentTouch - previousTouch;
}
I have got pt from ccTouchBegan the same way as pt1
Thanks