这个帖子是笔记,有想用C或C++语言开发游戏的可以加这个
掌柜的创的Cocos2d-x 学习群:153412944
Position(位置)的默认anchorPoint(描点)是(0.5,0.5)
anchorPoint(描点)的取值范围是0~1之间。
PS:示例的屏幕大小为480*320
文字的位置放在屏幕的正中。
C++关键代码:
[mw_shl_code=c,true] auto labela = LabelTTF::create ( "A","Arial", 31);
labela->setPosition ( Point ( Vec2 (240 , 160 )));
this->addChild ( labela, 1 );
auto labelb = LabelTTF::create ( "B", "Arial", 31);
labelb->setPosition ( Point ( Vec2 ( 240, 160 )));
labelb->setAnchorPoint ( Vec2 ( 0, 0 ));
this->addChild ( labelb,1);
auto labelc = LabelTTF::create ( "C", "Arial", 31);
labelc->setPosition ( Point ( Vec2 ( 240, 160 )));
labelc->setAnchorPoint ( Vec2 ( 0, 1 ));
this->addChild ( labelc,1);
auto labeld = LabelTTF::create ( "D", "Arial", 31);
labeld->setPosition ( Point ( Vec2 ( 240, 160 )));
labeld->setAnchorPoint ( Vec2 ( 1, 0 ));
this->addChild ( labeld,1);
auto labele = LabelTTF::create ( "E", "Arial", 31 );
labele->setPosition ( Point ( Vec2 ( 240, 160 )));
labele->setAnchorPoint ( Vec2 ( 1, 1 ));
this->addChild ( labele, 1 );[/mw_shl_code]
效果图:
|