-(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 度或更小。
任何帮助将不胜感激。