我在游戏中有一个车轮控制器,其设置如下:
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
if (CGRectContainsPoint(wheel.boundingBox, location))
{
CGPoint firstLocation = [touch previousLocationInView:[touch view]];
CGPoint location = [touch locationInView:[touch view]];
CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location];
CGPoint firstTouchingPoint = [[CCDirector sharedDirector] convertToGL:firstLocation];
CGPoint firstVector = ccpSub(firstTouchingPoint, wheel.position);
CGFloat firstRotateAngle = -ccpToAngle(firstVector);
CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);
CGPoint vector = ccpSub(touchingPoint, wheel.position);
CGFloat rotateAngle = -ccpToAngle(vector);
CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
wheelRotation += (currentTouch - previousTouch) * 0.6; //limit speed 0.6
}
}
我通过执行以下操作更新了更新方法中滚轮的旋转:
wheel.rotation = wheelRotation;
现在,一旦用户放开方向盘,我希望它旋转回原来的位置,但不是没有考虑用户滑动的速度。这是我真的无法理解的一点。因此,如果滑动产生大量的速度,那么轮子将继续沿该方向移动,直到将车轮拉回到起始位置的整体力量开始。
任何想法/代码段?
答案 0 :(得分:1)
限制车轮旋转+ = currentTouch - previousTouch;
我的意思是
if (currentTouch - previousTouch > wantedLimit) {
wheelrotation += wantedLimit;
}
else {
wheelrotation += currentTouch - previousTouch;
}