Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 具有触感加速度的旋转轮_Iphone_Cocos2d Iphone_Velocity_Momentum - Fatal编程技术网

Iphone 具有触感加速度的旋转轮

Iphone 具有触感加速度的旋转轮,iphone,cocos2d-iphone,velocity,momentum,Iphone,Cocos2d Iphone,Velocity,Momentum,我在游戏中有一个轮子控制装置,其设置如下: - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:[touch view]]; location = [[CCDirector sharedDirector] convertToGL:l

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

- (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;
现在,一旦用户松开方向盘,我希望它能旋转回到之前的位置,但不能不考虑用户的滑动速度。这是我真的无法理解的一点。因此,如果滑动产生了很大的速度,那么车轮将继续朝该方向轻微移动,直到将车轮拉回到起始位置的总力开始起作用


任何想法/代码片段?

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

if (currentTouch - previousTouch > wantedLimit) {
wheelrotation += wantedLimit;
}
else {
wheelrotation += currentTouch - previousTouch;
}

如果这完全是在核心动画中完成的,而不是cocos,你会同意吗?我需要它,这样它就可以在cocos2d框架内工作。真的,我只是无法理解数学。嗨,谢谢,我设法将车轮旋转限制为固定值0.5。我这样乘以:车轮旋转+=(currentTouch-previousTouch)*0.5;但第二部分仍然有问题。请尝试将旋转回原始位置的代码插入touchesend方法