1
votes

Please tell me if I got this wrong.

Anchor point is like a movable center of a sprite.
You specify a sprite's center by setting an anchor point.

Now you can place the sprite by specifying the position of the center.

ex)
anchor point = (1,1) : sprite's center is its right upper corner(I can think of it as "pinned at the right upper corner")
position = (screenWidth, screenHeight) : place the center(anchor point) at the (screenWidth, screenHeight)

Resulting in a sprite aligned at the top-right corner of the screen.

1

1 Answers

5
votes

strange name ("movable center"), but you are almost right. the only thing, that it is property of CCNode class, not CCSprite. Just by default CCNode has no contentSize and has isRelatieveAnchorPoint property to NO.

Another one point is that all transformations will be done relatieve to the anchor point. I mean, if you will set anchor point to, for example, (1.f, 1.f),place tour node(sprite) to the center of the screen and begin to change it's rotation(scale, etc.), it will rotate around it's anchor point.

And one interesting trick with anchor point. Nobody says that it's x and y values must be between 0.f and 1.f =) So, you can rather simply make your node(sprite) to move by circle, setting it's anchor point to the out part (for example, to (0.5f, -10.f)) and begin to rotate it. Your node(sprite) will move by circle with center in node.position(sprite.position) and radius of (10.5f * it's contentSize.height)