Objective c 旋转CCSprite以在Cocos2D中触摸

Objective c 旋转CCSprite以在Cocos2D中触摸,objective-c,cocos2d-iphone,Objective C,Cocos2d Iphone,我目前正在使用此代码旋转CCSprite(播放器)对象以面对最后一次触摸。问题是这使得旋转变得非常跳跃,而且看起来不太平滑 CGPoint playerPos = [player position]; CGPoint diff = CGPointMake(currentPoint.x-lastPoint.x, currentPoint.y-lastPoint.y); CGPoint playerNewPos = ccpAdd(playerPos, diff); [player setRotati

我目前正在使用此代码旋转CCSprite(播放器)对象以面对最后一次触摸。问题是这使得旋转变得非常跳跃,而且看起来不太平滑

CGPoint playerPos = [player position];
CGPoint diff = CGPointMake(currentPoint.x-lastPoint.x, currentPoint.y-lastPoint.y);
CGPoint playerNewPos = ccpAdd(playerPos, diff);
[player setRotation:-CC_RADIANS_TO_DEGREES(atan2(playerNewPos.y-playerPos.y, playerNewPos.x-playerPos.x))];
我怎样才能使这个代码更流畅

我也尝试过使用CCRotateTo,但它导致了相同的问题

提前感谢

试试这个:

float angle = -CC_RADIANS_TO_DEGREES(atan2(playerNewPos.y-playerPos.y, playerNewPos.x-playerPos.x));
id action=[CCRotateTo actionWithDuration:1.0 angle:angle];
[player runAction:[CCEaseInOut actionWithAction:action rate:3]]

这里得到新老触摸位置如下

- (void)registerWithTouchDispatcher
{
    [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:
           self priority:0 swallowsTouches:YES];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    return YES;
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{

    CGPoint touchLocation = [self convertTouchToNodeSpace:touch];

     NSLog(@"touch end ==%f-----%f",touchLocation.x,touchLocation.y);

    // Save old location to NSuserDefault And get new From Above

}
现在按照如下位置旋转

int offX = (CurrentTouch.x - OldTouch.x);
int offY = (CurrentTouch.y - OldTouch.y));

float angleRadians = atanf((float)offX / (float)offY);
float angleDegrees = CC_RADIANS_TO_DEGREES(angleRadians);

id action=[CCRotateTo actionWithDuration:1.0 angle:angleDegrees];
[player runAction:action];