cocos2dx定时器scheduleUpdate研究
直接发源代码
#include <iostream> #include <windows.h> using namespace std; class Ref { protected: Ref(){isLoop = false;} virtual void update(){cout<< "super loop" << endl;} bool isLoop; public: void unScheduleUpdate(){isLoop = false;} void ScheduleUpdate(){isLoop = true;} void mainLoop(){if (isLoop)this->update();} }; class myClass :public Ref { public: virtual void update(){cout << "this loop" << endl;} }; int main(int argc, char* argv[]) { Ref*ref = new myClass; ref->ScheduleUpdate(); for (;;) { cout << "loop" << endl; Sleep(500); ref->mainLoop(); ref->unScheduleUpdate(); } return(0); }
其结果和cocos scheduleUpdate定时器 功能一致,
这个问题困扰了很久,原因是c++基础更不扎实,该功能是典型的虚函数应用