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