2
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
    {
        CGPoint location = [touch locationInView:[touch view]];
        location = [[CCDirector sharedDirector] convertToGL:location];

        shootVector = ccpSub(location, cannon.position);
        CGFloat shootAngle = ccpToAngle(shootVector);
        cocosAngle = CC_RADIANS_TO_DEGREES(-1 * shootAngle);

        CGFloat rotateDiff = cocosAngle;    
        if (rotateDiff > 180)
            rotateDiff -= 360;
        if (rotateDiff < -180)
            rotateDiff += 360;    

        CGFloat rotateSpeed = 360; 
        rotateDuration = fabs(rotateDiff / rotateSpeed);

        [cannon runAction:[CCSequence actions:
                           [CCRotateTo actionWithDuration:rotateDuration angle:cocosAngle],
                           [CCCallFunc actionWithTarget:nil selector:nil],
                           nil]];

        top.rotation = cannon.rotation;
    }

上面的代码导致触摸时旋转 360 度,而不是我想将我的大炮旋转 180 度或更小。

任何帮助将不胜感激。

4

1 回答 1

2

使用CCRotateBy命令而不是CCRotateTo将导致旋转一定量而不是转到某个位置。以与 CCRotateTo 相同的方式调用它,如下所示:

[CCRotateBy actionWithDuration:rotateDuration angle:180]
于 2013-04-18T17:00:37.513 回答