搜索
查看: 478|回复: 0
打印 上一主题 下一主题

【cocos2d-x】Node的Position和anchorPoint属性

[复制链接]
跳转到指定楼层
楼主
发表于 2016-5-10 18:26:26 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
这个帖子是笔记,有想用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]

效果图:


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表