Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:18:11+00:00 2026-05-23T01:18:11+00:00

Does anyone have a better way to rotate a sprite with one finger? My

  • 0

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.

Any one have any better ideas than this?

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;
        }
    }

Thanks

EDIT:

I went in to GameConfig.h and changed #define GAME_AUTOROTATION kGameAutorotationUIViewController to #define GAME_AUTOROTATION kGameAutorotationNone

Then, went in to AppDelegate.m and changed #if GAME_AUTOROTATION == kGameAutorotationUIViewController to #if GAME_AUTOROTATION == kGameAutorotationNone

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:18:11+00:00Added an answer on May 23, 2026 at 1:18 am

    add a new line at the end:

    gRotation += currentTouch - previousTouch;
    gRotation = fmod(gRotation,360.0); // <<< fix the angle
    

    this maybe fix your problem, because the angle will stay in the 360 range

    Other way to rotate with one finger is the UIPanGestureRecognizer (but you still need to keep the angle in the 360 range):

    UIPanGestureRecognizer *gestureRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePanFrom:)] autorelease];
    [[[CCDirector sharedDirector] openGLView] addGestureRecognizer:gestureRecognizer];
    
    ...
    
    - (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer 
    {
      CGPoint translation = [recognizer translationInView:recognizer.view];
      ...
    }
    

    Take a look at this tutorial for more details (its on drag, but show how to do the pan gesture):

    http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know, or better yet have an example, of a WCF service that
Does anyone have a suggestion on a better way to intercept a properties with
Does anyone have any recommendations of tools that can be of assistance with moving
This code works, but its very old-schoolish looking. Does anyone have a better way
Does anyone have any advice on which method is better when caching data in
does anyone have a nice solution to get de price wich is a variable
Can anyone please help. I have a problem where I need to loop through
Does anyone have any advice for a consistent way to unit test a multithreaded
Does anyone have any experience in documenting/structuring angularjs projects so the JSDoc can generate
Does anyone have a translate function for x/y positions after rotation in javascript? for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.