0

私は現在、このコードを使用して 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 も使用してみましたが、同じ問題が発生しています。

前もって感謝します

4

2 に答える 2

0

ここでは、以下のように古いタッチ位置と新しいタッチ位置を取得します

- (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];
于 2013-10-15T05:48:19.720 に答える
0

これを試して:

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]]
于 2013-10-12T10:58:23.147 に答える