直接发源代码
#include<iostream> #include<windows.h> usingnamespacestd; classRef { protected: Ref(){isLoop=false;} virtualvoidupdate(){cout<<"superloop"<<endl;} boolisLoop; public: voidunScheduleUpdate(){isLoop=false;} voidScheduleUpdate(){isLoop=true;} voidmainLoop(){if(isLoop)this->update();} }; classmyClass:publicRef { public: virtualvoidupdate(){cout<<"thisloop"<<endl;} }; intmain(intargc,char*argv[]) { Ref*ref=newmyClass; ref->ScheduleUpdate(); for(;;) { cout<<"loop"<<endl; Sleep(500); ref->mainLoop(); ref->unScheduleUpdate(); } return(0); }
其结果和cocos scheduleUpdate定时器 功能一致,