I am a bit confused about how to position a CCNode
. For example, I would like to position the node at the top right of the screen, but down a bit from the top. How would I do this?
I was thinking:
getCoins->setAnchorPoint(ccp(0,0));
getCoins->setPosition( ccp(0,1) );
But that didn't work.
Could someone explain how to do positioning like this?
In cocos2d-x, the origin (x=0, y=0) is in the bottom-left corner of screen, so X axis starts from the left side and increases to right and Y axis starts from bottom of screen and moves upward.
The anchor point is used for both positioning and rotating an object. An anchor point ranges from between 0, 0
to 1, 1
. An anchor point of 0.5, 0.5
is the center of object.
So for example if you are placing a object with anchor point 0.5, 0.5
to 100, 100
on screen the center of object will be placed on 100, 100
.
For more details about coordinate system and anchor points check here