Game Development Reference
In-Depth Information
anchorPoint , you change only where the texture of the node is drawn relative to the
node's position. But that also raises the question: why would you want to modify the
anchorPoint , and what effects can you achieve by doing so?
For example, setting the anchorPoint to 0,0 effectively moves the texture so that its
lower left-hand corner aligns with the node's position. If you set the anchorPoint to
1,1 instead, the top right-hand corner of the texture will align with the node's position.
Sometimes this can be useful to align textures with the screen borders or other ele-
ments; specifically, it's useful as a way for CCLabel classes to right-align or top-align
the text, for example.
Generally, you don't want to modify the anchorPoint unless you have a good reas-
on to do so, because it can have wide-ranging side effects such as offsetting position-
based collision checks. It also has an effect on rotation and scaling because the texture
will no longer be rotated or scaled around its center position.
I know of three situations where changing the anchor point may be helpful:
To align nodes with the screen window borders more easily.
To right/left/top/bottom-align a label, button, or image.
To align an image whose size was changed without having to modify
the sprite's position.
In all other cases use the position property of the node.
In the following example code, the sprite image will neatly align with the lower left-
hand corner of the screen because its anchorPoint is set to 0,0, which causes the
texture's lower left-hand corner to align with the sprite's default position , which is
also 0,0:
CCSprite* sprite = [CCSprite spriteWithFile:@"Default.png"];
sprite.anchorPoint = CGPointMake(0, 0);
[self addChild:sprite];
Search Nedrilad ::

Custom Search