COCOS2DX Learning Note 11:COCOS2DX Scheduler (Scheduler)

Source: Internet
Author: User

Scheduler (Scheduler) is mainly for the game to provide timed events and timing services. Often used to play some of the functions of timed processing, such as some logic judgment, collision detection and so on.


COCOS2DX provides three commonly used schedulers (scheduler) for us to use.

Default Scheduler (schedulerupdate)

The default scheduler uses the Refresh event Update method of node, which is called once before each frame is drawn. Because the time interval between frames is short, each frame refresh is sufficient to complete the logical judgment required for most of the gameplay.


when we use the default scheduler (schedulerupdate), we need to overload Node of the Update method to execute its own logic code. If you need to stop this scheduler, you can use the Unschedulerupdate () method.


use time to override the Update method in the. h file First: void update (float dt).

call the implementation of update using the Scheduleupdate () method directly where it is called.

Custom Scheduler (Scheduler)

Sometimes the engine comes with a scheduler that doesn't fit our needs, so we need to define the scheduler ourselves. This method is provided by COCOS2DX.

Schedule (sel_schedule selector, float interval, unsigned int repeat, float delay)

the first parameter, selector, is the event function you want to add.

the second parameter, interval, is the event firing interval.

The third parameter, repeat, is the number of times a trigger is triggered after an event, and the default value is Krepeatforever, which indicates the number of infinite triggers.

the fourth parameter, delay, indicates the delay before the first trigger.

Single-Time Scheduler (scheduleronce)

The Cocos2d-x also provides a single-time scheduler with only one dispatch.

scheduleonce (Schedule_selector (helloworld::updateonce), 0.1f);



Here I use Laberttf to implement a number +1 Self-growth default scheduler, to dynamically change the value of Labelttf.

650) this.width=650; "Title=" Click to view the original "border=" 0 "alt=" study note 11: Figure 1.gif "src=" http://www.byjth.com/content/uploadfile/ 201509/7d151442560270.gif "width=" 607 "height=" 577 "/>


COCOS2DX Learning Note 11:COCOS2DX Scheduler (Scheduler)

Http://www.byjth.com/biji/31.html


This article is from the "Close your eyes on the Dark" blog, please be sure to keep this source http://byjth.blog.51cto.com/4127898/1758983

COCOS2DX Learning Note 11:COCOS2DX Scheduler (Scheduler)

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.