title: Rotating Sprite with Touch - Cocos2d
body: <p>Does anyone have a better way to rotate a sprite with one finger?  My problem is that I can not get the sprite to stop rotating after it has been fully rotated twice and I flip my screen 180 degree periodcally (self.rotation = 180;) then flip it back (self.rotation = 0).  But, when I flip it to 180 degrees the sprite will not rotate properly.</p>
  
  <p>Any one have any better ideas than this?</p>
  
  <pre><code>CGFloat gRotation;
  
  - (void)update:(ccTime)delta
  {
      g.rotation = gRotation;
  }
      - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
      {
          UITouch *touch = [touches anyObject];
          CGPoint location = [touch locationInView:[touch view]];
          location = [[CCDirector sharedDirector] convertToGL:location];
  
          if (CGRectContainsPoint(g.boundingBox, location))
          {
              CGPoint firstLocation = [touch previousLocationInView:[touch view]];
              CGPoint location = [touch locationInView:[touch view]];
  
              CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location];
              CGPoint firstTouchingPoint = [[CCDirector sharedDirector] convertToGL:firstLocation];
  
              CGPoint firstVector = ccpSub(firstTouchingPoint, g.position);
              CGFloat firstRotateAngle = -ccpToAngle(firstVector);
              CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);
  
              CGPoint vector = ccpSub(touchingPoint, g.position);
              CGFloat rotateAngle = -ccpToAngle(vector);
              CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
  
              gRotation += currentTouch - previousTouch;
          }
      }
  </code></pre>
  
  <p>Thanks</p>
  
  <p><em><strong>EDIT:</em></strong></p>
  
  <p>I went in to GameConfig.h and changed <code>#define GAME_AUTOROTATION kGameAutorotationUIViewController</code> to <code>#define GAME_AUTOROTATION kGameAutorotationNone</code></p>
  
  <p>Then, went in to AppDelegate.m and changed <code>#if  GAME_AUTOROTATION == kGameAutorotationUIViewController</code> to <code>#if GAME_AUTOROTATION == kGameAutorotationNone</code></p>
  
  <p>That fixed the sprite's rotation when I flipped the screen, but I am still having problems stopping the sprite's rotation after two full rotations.</p>