有什么方法可以旋转 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 中有没有办法做到这一点?