1
我有一个CCNode与一定的旋转。为了简单起见,可以说它旋转了45度,尺寸是100 * 100,位置是200,200。如何获得旋转的CCNode的角坐标?
我期待找到4个坐标(标记为绿色)在该图像上。在框架中是否有任何方法可以用于此操作,还是需要用三角函数手动执行?在那种情况下,我该怎么做最简单的方法?
的最好的事情是,如果我能做出这样的CCNode类,所以它的方便的方法。
我有一个CCNode与一定的旋转。为了简单起见,可以说它旋转了45度,尺寸是100 * 100,位置是200,200。如何获得旋转的CCNode的角坐标?
我期待找到4个坐标(标记为绿色)在该图像上。在框架中是否有任何方法可以用于此操作,还是需要用三角函数手动执行?在那种情况下,我该怎么做最简单的方法?
的最好的事情是,如果我能做出这样的CCNode类,所以它的方便的方法。
CCNode.h:
/** Converts a Point to world space coordinates. The result is in Points.
@since v0.7.1
*/
- (CGPoint)convertToWorldSpace:(CGPoint)nodePoint;
/** Converts a Point to node (local) space coordinates. The result is in Points.
@since v0.7.1
*/
- (CGPoint)convertToNodeSpace:(CGPoint)worldPoint;
例子:
// top right corner of your node
CGPoint topRight = ccp(node.contentSize.width, node.contentSize.height);
// same point in world coordinates
CGPoint topRightWorld = [node convertToWorldSpace:topRight];
试试这个:
CGFloat angle = node.rotation * M_PI/180;
CGRect frame = CGRectMake(node.position.x, node.position.y, node.contentSize.width, node.contentSize.height);
CGPoint ip0 = CGPointMake(frame.origin.x,frame.origin.y);
CGPoint ip1 = CGPointMake(frame.origin.x +frame.size.width, 0);
CGPoint ip2 = CGPointMake(0,frame.origin.y +frame.size.height);
CGPoint ip3 = CGPointMake(frame.origin.x +frame.size.width,frame.origin.y +frame.size.height);
ip0 = CGPointApplyAffineTransform(ip0, CGAffineTransformMakeRotation(angle));
ip1 = CGPointApplyAffineTransform(ip1, CGAffineTransformMakeRotation(angle));
ip2 = CGPointApplyAffineTransform(ip2, CGAffineTransformMakeRotation(angle));
ip3 = CGPointApplyAffineTransform(ip3, CGAffineTransformMakeRotation(angle));
感谢你的努力。这可能也适用,如果你不使用CCNode或它的任何基类,这可能是要走的路。 – 2012-08-16 13:57:31