How can I display the anchorpoint for a CCNode in

2019-05-22 15:31发布

Is there a way to display a CCNode's anchor point? This would be very useful for debugging.

2条回答
霸刀☆藐视天下
2楼-- · 2019-05-22 16:02

You can access the anchor point of a CCNode with

- (CGPoint) anchorPointInPixels

which is a readonly method. Afterwards, you have several ways of actually marking the spot. You could use

- ccDrawCircle()

while overriding the draw method or alternatively put up a texture on that point, if you want something fancier.

查看更多
Explosion°爆炸
3楼-- · 2019-05-22 16:18

Not built-in, but you could draw a point or circle at the anchor point location using the anchorPointInPoints property.

-(void) draw
{
    [super draw];
    ccDrawCircle(self.anchorPointInPoints, 20, 0, 8, YES);
}

Of course, I always recommend not to change the anchorPoint in the first place. The alternative is to add the node to a parent node, offset it from the parent, and then the parent's position acts like the anchorpoint for the child node. The advantage is that methods like boundingBox aren't offset from the node's position (can be an issue for hit detection), and you can rotate the child node around its center point and around its parent.

查看更多
登录 后发表回答