Cocos2d-x Schedule Timer Use example _c language

Source: Internet
Author: User

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));
 }
}

Related Article

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.