0

有什么方法可以旋转 CCSprite 使其表现得像汽车转向?如果我松开 CCSprite 的触摸,它应该会像转向一样平滑地自动返回到原来的位置!我使用下面的代码,

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {

        UITouch *touch=[touches anyObject];
        //acquire the previous touch location
        CGPoint firstLocation = [touch previousLocationInView:[touch view]];
         location = [touch locationInView:[touch view]];


        CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location];
        CGPoint firstTouchingPoint = [[CCDirector sharedDirector] convertToGL:firstLocation];

        CGPoint firstVector = ccpSub(firstTouchingPoint, Steering.position);
        CGFloat firstRotateAngle = -ccpToAngle(firstVector);
        CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);

        CGPoint vector = ccpSub(touchingPoint, Steering.position);
        CGFloat rotateAngle = -ccpToAngle(vector);
        CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
        dialrotation+=currentTouch-PreviousTouch;
        sprite.rotation=dialrotation;
        }

这可以平滑地旋转我的 CCSprite,但我不知道如何像汽车转向一样回到原来的位置。在 Cocos2D 中有没有办法做到这一点?

4

1 回答 1

0

ccTouchesBegan方法中将 sprite.rotation 的值存储在某处,在使用此存储值对您的精灵ccTouchesEnded运行操作中。CCRotateTo

于 2012-08-26T03:38:01.097 回答