Schedule can realize the function of the timer, is to do something every once in a while, schedule caller is a node, all nodes can call the schedule function, parameters need to pass in a function (Schedule_selector a new selector), In the function can complete the collision detection and so on function. Here is a concrete look at the use of this function bar.
BOOL Helloworld::init () {bool BRet = false; do {cc_break_if (!
Cclayer::init ());
The show function//this->schedule (Schedule_selector (helloworld::show)) is invoked for each frame when schedule passes in a parameter;
In the following schedule method, the second parameter passed in is the time, representing how long it is to call the show function//this->schedule (Schedule_selector (helloworld::show), 1.0); The first two arguments in the schedule method are the same as the top, and the third is the number of repetitions of the method call, repeating the first///Total Call of two times plus three times, and 3.0 representing how long it is to start calling a function after executing the following statement, which is the time of the delay//this-
>schedule (Schedule_selector (helloworld::show), 1.0,2,3.0);
Scheduleupdate calls the Update method every other frame, we need to declare the Update method This->scheduleupdate ();
BRet = true;
while (0);
return bRet;
} void Helloworld::update (float dt) {static int i = 0;
if (i = = 100) {//The next time the Update method is not called, the Cclog function will still execute.
This->unscheduleupdate ();
The following function implements the same function, which stops calling This->unscheduleallselectors () on the schedule method of this layer;
} cclog ("I =%d", ++i);
The//show function must contain a float-type parameter void Helloworld::show (float dt) {static int i = 0;
Cclog ("time =%d", ++i); if (i = =) {//unschedule Stop incoming parameter generationThe method call of the table//The following code does not necessarily need to be written in this show Method This->unschedule (Schedule_selector (helloworld::show));
}
}