Cocos2d-x 3.0final09-绘图节点Node
1、在当前的HelloWorldScne.h中添加一个方法在HelloWorldScene
如:
void gameLogic(float t); //注意这里的参数要设置为float
2、在HelloWorldScene::init方法添加以下代码:
this->schedule(schedule_select(HelloWorldScene::gameLogic),0.5);
还有把label设置一个tag
label->setTag(110);
3、在HelloWorldScne.cpp中实现这个方法
void HelloWorldScene::gameLogic(float t){
//在这里修改 HelloWorld 对应的Label的坐标
auto theLabel=this->getChildByTag(110);
theLabel->runAction(MoveBy::create(5,0.5));
if(theLable->getPositionX()>480){theLabel->setPositionX(0);}
}
这样就实现了HelloWorld的自动向右移动,每0.5秒移动5像素。
这里使用了runAction,实际上直接通过theLabel->setPositionX(newX)也可以,我们可以在这里修改Node的各种属性以达到对场景中的Node变换的作用。
Action是对Node变换的封装,下一节介绍。
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:69
阅读量:110
阅读量:126
阅读量:174
阅读量:32