Cocos2D-x游戏开发之二十一:ScheduleUpdate 跟ScheduleOne的用法

Cocos2D-x游戏开发之二十一:ScheduleUpdate 和ScheduleOne的用法

今天接着学习了Coco2D-x的定时器,Cocos2D为我们封装好了定时器功能,我们只需要再用到的地方直接使用:

     schedule可以直接使用,即采用默认方式在init()函数里面调用:this->scheduleupdate();并重新定义Update()即可。

    也可以调动this-.>schedule(schedule_selector(HelloWorld::MYUpdate),3.0f)然后实现MYUpdate函数即可实现每3.0f调用一次MYUpdate函数。

   同原样我们也可以之让一个函数在特定的时间只运行一次:this->scheduleOnce(schedule_selector(HelloWorld::MYUpdate),3.0f);

   

                this->scheduleUpdate();
		this->schedule(schedule_selector(HelloWorld::updateForMe),2.0f);
		this->scheduleOnce(schedule_selector(HelloWorld::updateForMe),2.0f);