[英]CCSprite rotation like Car Steering in Cocos2D
有什么方法可以使CCSprite旋转为类似于汽车转向系统吗?如果我松开CCSprite的触摸,它将自动以平滑的方式自动返回其原始位置,就像转向一样!Im使用以下代码,
-(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,但是我不知道如何像Car Steering一样返回到其原始位置。在Cocos2D中有什么方法可以这样做吗?
在ccTouchesBegan
方法中,将ccTouchesBegan
的值存储在某个位置,在ccTouchesEnded
使用此存储的值对您的sprite运行CCRotateTo
操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.