position(位置)属性是Node对象的实际位置。position属性每每还要配合使用anchorPoint属性,为了将一个Node对象(标准矩形图形)精准的放置在屏幕某一个位置上,须要设置该矩形的锚点,anchorPoint是相对于position的比例,默认是(0.5,0.5)。咱们看看下面的几种状况:html
以anchorPoint为(0.5,0.5)为例,这是默认状况。函数
下面是anchorPoint为(0.0,0.0)状况。字体
下面是anchorPoint为(1.0,1.0)状况。this
下面是anchorPoint为(0.5,0.66)状况。spa
为了进一步了解anchorPoint使用,咱们修改HelloWorld实例,修改HelloWorldScene.cpp的HelloWorld::init()函数以下,其中加粗字体显示的是咱们添加的代码。.net
[html] view plaincopycode
<span style="font-size:14px;">bool HelloWorld::init() orm
{ htm
… … 对象
auto label = LabelTTF::create("Hello World","Arial", 24);
label->setPosition(Point(origin.x + visibleSize.width/2,
origin.y +visibleSize.height - label->getContentSize().height));
label->setAnchorPoint( Point(1.0, 1.0) );
this->addChild(label, 1);
auto sprite = Sprite::create("HelloWorld.png");
sprite->setPosition(Point(visibleSize.width/2 + origin.x,visibleSize.height/2 + origin.y));
this->addChild(sprite, 0);
return true;
}</span>
Hello World设置了anchorPoint为(1.0,1.0)。