-(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次以下..如何旋转180度cocos2d-iphone的精灵?
任何帮助,将不胜感激。
最多可创建和Minmum degres,并与他们比较,如果rotateDiff> MaxDegree然后设置为MAX如果rotateDiff