我认为最好的方法是获取两个参考点,一个代表原点,另一个代表旋转矢量。将这 2 个点转换为节点空间,测量它们之间的向量(减法)并将其转换为角度。这里有2个方法应该是CCNode的一个类别(注意:我指的是self),一个到world,另一个到node。
-(float) convertRotationToWorldSpace:(float)rotation
{
CGPoint rot = ccpForAngle(-CC_DEGREES_TO_RADIANS(rotation));
CGPoint worldPt = [self convertToWorldSpace:rot];
CGPoint worldOriginPt = [self convertToWorldSpace:CGPointZero];
CGPoint worldVec = ccpSub(worldPt, worldOriginPt);
return -CC_RADIANS_TO_DEGREES(ccpToAngle(worldVec));
}
-(float) convertRotationToNodeSpace:(float)rotation
{
CGPoint rot = ccpForAngle(-CC_DEGREES_TO_RADIANS(rotation));
CGPoint nodePt = [self convertToNodeSpace:rot];
CGPoint nodeOriginPt = [self convertToNodeSpace:CGPointZero];
CGPoint nodeVec = ccpSub(nodePt, nodeOriginPt);
return -CC_RADIANS_TO_DEGREES(ccpToAngle(nodeVec));
}