title: Set angle of sprite (rotate) in cocos2d
body: <p>I am new in cocos2d game development. I've set a Turret on the screen. When we touch the screen, the turrets fire bullets, but my turret's angle is not set correctly. This code is taken from the raywenderlich tutorial series. Also, bullets are not passing by the touched point.</p>
  
  <p>Below is my code.</p>
  
  <p><img src="https://i.stack.imgur.com/gkOOF.jpg" alt="Screenshot"></p>
  
  <pre><code> // Determine offset of location to projectile
      CGPoint offset = ccpSub(cointouchLocation,turretArms.position);
  
      NSLog(@"offset: %@",NSStringFromCGPoint(offset));
  
      // Bail out if you are shooting down or backwards
  
      if (offset.x &lt;= 0) return;
      int realX = winSize.width +(turretArms.contentSize.width/2);
      float ratio =  (float) offset.y/(float) offset.x;
      int realY =(realX * ratio) +turretArms.position.y;
      CGPoint realDest = ccp(realX, realY);
  
      // Determine the length of how far you're shooting
      int offRealX = realX - turretArms.position.x;
      int offRealY = realY - turretArms.position.y;
      float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
       float velocity = 480/1;
      float realMoveDuration = length/velocity;
  
  
  
  
      // Determine angle to face
     float angleRadians = atanf((float)offRealY / (float)offRealX);
  
     // NSLog(@"angleRadians : %f",angleRadians);
      float angleDegrees = CC_RADIANS_TO_DEGREES(angleRadians);
      float cocosAngle = -1 * angleDegrees;
      float rotateDegreesPerSecond = 180 / 0.5; // Would take 0.5 seconds to rotate 180 degrees, or half a circle
      float degreesDiff = turret.rotation - cocosAngle;
      float rotateDuration = fabs(degreesDiff / rotateDegreesPerSecond);
      [turret runAction:
       [CCSequence actions:
        [CCRotateTo actionWithDuration:rotateDuration angle:cocosAngle],
        [CCCallBlock actionWithBlock:^{
           // OK to add now - rotation is finished!
           [self addChild:turretArms];
           [turretsAry addObject:turretArms];
  
           // Release
           [turretArms release];
           turretArms = nil;
       }],
        nil]];
  
      // Move projectile to actual endpoint
      [turretArms runAction:
       [CCSequence actions:
        [CCMoveTo actionWithDuration:realMoveDuration position:realDest],
        [CCCallBlockN actionWithBlock:^(CCNode *node) {
           [turretsAry removeObject:node];
           [node removeFromParentAndCleanup:YES];
       }],
        nil]];
  
      turretArms.tag =2;
  
      //coin delete from window
  
      for (CCSprite *cmonster in coinmonstersToDelete) {
          // [monster stopAllActions];
          [coinmonstersOnScreen removeObject:cmonster];
          [self removeChild:cmonster cleanup:YES];
  
      }
  </code></pre>