‎Cocos2d-x 3.x 学习笔记(三):Scheduler Timer 调度与定时

Cocos2d-x 的 Scheduler 离不开 Timer。Timer 类是定时器,用来规定一个回调函数应该在何时被触发。Timer 封装了已运行时间、重复次数、已执行次数、延迟秒数、时间间隔、要触发的回调函数等等,都是与一个回调函数触发相关的成员。

Scheduler 是调度器,用来对 Timer 进行调度,Timer 只是定义了回调函数的触发条件、触发次数等,真正的触发动作由 Scheduler 执行。

2. Timer 和 TimerTargetSelector、TimerTargetCallback

Timer 的成员:

class CC_DLL Timer : public Ref {void setupTimerWithInterval(float seconds, unsigned int repeat, float delay); // void setAborted() { _aborted = true; } bool isAborted() const { return _aborted; } bool isExhausted() const; virtual void trigger(float dt) = 0; virtual void cancel() = 0; void update(float dt); Scheduler* _scheduler; // weak ref float _elapsed; // 已运行时间 bool _runForever; // 是否永远运行 bool _useDelay; // 是否使用延迟 unsigned int _timesExecuted; // 已执行次数 unsigned int _repeat; // 规定执行次数, 0 = once float _delay; // 延迟 float _interval; // 时间间隔 bool _aborted; // fff };

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsppjy.html