#Cocos2d-x-基本概念-Scheduler and Timer Callback
Scheduler的目的是按时出发被安排好的callback
###两种不同类型的callback(selector)
- update selector:每一帧都会被调用
- custom selector:可以指定每两次调用间隔的时间
custom selector应当尽少使用,使用update selector更加快速高效
###CCScheduler vs. NSTimer
CCScheduler是cocos2d内置的计时器,你不应使用Cocoa中的NSTimer
原因如下:
- callback在CCnode被从Scene上移除后会自动消失
- 游戏暂停时Scheduler也会暂停
- CCScheduler可以得到从上一帧到现在的间隔时间
- 用
this->scheduleUpdate()
可以确保在每一帧被渲染之前所有callback被调用