Set the anchor point of CCLayer

Set the anchor point of CCLayer
0.0 0


I have a simple class that extends CCLayer. The constructor looks like so:

         //setup anchorpoint
         //initialize the sun
         sun = Sun::create(world, 20);
         CCSprite *sprite = CCSprite::create("Icon.png");

When I add the sprite to the layer it is added as if the anchor point is still ccp(0,0). How can I set the anchor point of the layer to ccp(0.5,0.5)? Also, bonus question, how do I format code properly to display in the forum?


CCLayer’s init method calls ignoreAnchorPointForPosition(true); If you call ignoreAnchorPointForPosition(false) then the anchor point will be respected.


@a vm, I have modified your post to make the code display correctly. You can click “edit” and see how it works.


I just arrived over this issue and I would like to ask what is the reason for keep this default value as true.

I mean, why the default value is false for sprites and true for layers?