Set the anchor point of CCLayer

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

Space::Space()
{
         //setup anchorpoint
         this->setAnchorPoint(ccp(0.5,0.5));
         //initialize the sun
         sun = Sun::create(world, 20);
         sun->setPosition(ccp(0,0));
         sun->retain();
         this->scheduleUpdate();
         this->setTouchEnabled(true);
         //sprite
         CCSprite *sprite = CCSprite::create("Icon.png");
         this->addChild(sprite);
}

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.

1 Like

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

Hi!
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?