Cocos2d-x 3.0final09-绘图节点Node

时间:2026-02-15 20:36:57

1、1。在当前的HelloWorldScne.h中添加一个方法在HelloWorldScene

   如:

       void gameLogic(float t);  //注意这里的参数要设置为float

2、2.在HelloWorldScene::init方法添加以下代码:

    this->schedule(schedule_select(HelloWorldScene::gameLogic),0.5);

  还有把label设置一个tag

  label->setTag(110);

3、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变换的封装,下一节介绍。

© 2026 一点资料
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com