[Wood Cocos2d-x 034] I'm a timer (Chapter 1)-schedule for a real timer

Source: Internet
Author: User

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 !)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.