As a follow-on question to my previous question about displaying the anchor point, I subclassed CCSprite and changed its draw method as follows:
[super draw];
ccDrawColor4F(0, 1, 0, 1);
ccDrawCircle(self.anchorPointInPoints, 20, 0, 8, YES);
This works great. For extra credit, I added the following to display its bounding box:
CGRect bb = self.boundingBox;
CGPoint vertices[4] = {
[self convertToNodeSpace:ccp(bb.origin.x, bb.origin.y)],
[self convertToNodeSpace:ccp(bb.origin.x + bb.size.width, bb.origin.y)],
[self convertToNodeSpace:ccp(bb.origin.x + bb.size.width, bb.origin.y + bb.size.height)],
[self convertToNodeSpace:ccp(bb.origin.x, bb.origin.y + bb.size.height)],
};
ccDrawPoly(vertices, 4, YES);
This also works great, until I reparent a sprite:
CGPoint oldPosition = [sprite convertToWorldSpace:sprite.position];
[sprite removeFromParentAndCleanup:NO];
[parentSprite addChild:sprite];
sprite.position = [sprite convertToNodeSpace:oldPosition];
The sprite's now in the proper position and its anchor point draws where it should, but the bounding box draws in the wrong place. What am I doing wrong?