0

我在游戏中有一个滚轮控制,设置如下:

- (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;

现在,一旦用户松开滚轮,我希望它旋转回原来的位置,但不能不考虑用户所做的滑动速度。这是我真的无法理解的一点。因此,如果滑动产生很大的速度,那么车轮将继续沿该方向轻微移动,直到将车轮拉回起始位置的整体力开始起作用。

任何想法/代码片段?

4

1 回答 1

1

限制轮子旋转 += currentTouch - previousTouch;
我是说

if (currentTouch - previousTouch > wantedLimit) {
wheelrotation += wantedLimit;
}
else {
wheelrotation += currentTouch - previousTouch;
}
于 2012-06-30T22:32:48.570 回答