I am the timer chapter 03rd-Schedule of the real timer
The "timer" introduced in the previous section is a bit irregular. This time I will introduce you to a very timed timer.
(I think the logic is incorrect)
What do you mean? Flowers? No, it's your heart ~
Reprinted please note, original address: http://blog.csdn.net/musicvs/article/details/8551066
Body:
1. Do not call the UPDATE function. Call your own function.
In fact, the principle is the same. When we call scheduleupdate, the system calls the UPDATE function every frame by default. But what if we want to call our own function? It's easy to add a function to helloworldscene:
PRIVATE:/* Custom update function */void mutupdate (float fdelta );
Also log in the function:
void HelloWorld::MutUpdate( float fDelta ){CCLOG("MutUpdate");}
Then we will add a very violent code:
Bool helloworld: Init () {bool Bret = false; do {cc_break_if (! Cclayer: Init (); // This-> scheduleupdate ();/* specify the custom function to be executed per frame */This-> schedule (schedule_selector (helloworld :: mutupdate); Bret = true;} while (0); Return Bret ;}
We use schedule to specify a custom function. Then we run the project in debug mode and we will see the following output:
Mutupdate
Mutupdate
Mutupdate
Mutupdate
Mutupdate
Mutupdate
Mutupdate
Mutupdate
I think there is nothing to explain, that is, a callback function is specified.
(Xiao RuO: He doesn't understand it .)
2. Real timing
Well, we have to create a timer. Let's modify the schedule parameter:
this->schedule(schedule_selector(HelloWorld::MutUpdate), 1.0f);
The second parameter indicates the number of seconds to execute the mutupdate function. Remember, the unit is seconds.
There is also a more powerful timer that I can't help but introduce to you!
(Good !)
Listen to the next section.
(Xiao RuO: Your sister paper !)