Note that there are some explanatory texts on larger screens.

plurals
  1. PORotating a sprite with Touch - Cocos2d
    text
    copied!<p>I know this question has been asked several times, trust me I have searched. I have found one answer to rotating a sprite with touch, but there has to be a simpler way.</p> <p>All I need is for my sprite to rotate with my touch. Max rotation 0 Minimum rotation 0.</p> <p>I know that I'll need a few checks. </p> <pre><code>int maxRot = 0; int minRot = 0; if (arrowRotation &gt; maxRot) { //do or don't do something } else if (arrowRotation &lt; minRot) { //do or don't do something } </code></pre> <p>Can someone lead me in the right direction to rotating a sprite with touch, with a minimun and maximum rotation?</p> <p>Here is the code that I think is to complicated or can be accomplished in a simpler way.</p> <pre><code>-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; //acquire the previous touch location CGPoint firstLocation = [touch previousLocationInView:[touch view]]; CGPoint location = [touch locationInView:[touch view]]; //preform all the same basic rig on both the current touch and previous touch CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location]; CGPoint firstTouchingPoint = [[CCDirector sharedDirector] convertToGL:firstLocation]; CGPoint firstVector = ccpSub(firstTouchingPoint, _arrow.position); CGFloat firstRotateAngle = -ccpToAngle(firstVector); CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle); CGPoint vector = ccpSub(touchingPoint, _arrow.position); CGFloat rotateAngle = -ccpToAngle(vector); CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle); //keep adding the difference of the two angles to the dial rotation arrowRotation += currentTouch - previousTouch; } </code></pre> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload