How can I display the anchorpoint for a CCNode in cocos2d?

≯℡__Kan透↙ 提交于 2019-12-22 12:09:07

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12125796/how-can-i-display-the-anchorpoint-for-a-ccnode-in-cocos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!