1. cocos-2d node上面的 schedule


/**
* Schedules a lambda function.
*
* @param callback  The lambda function to be schedule.
* @param interval  Tick interval in seconds. 0 means tick every frame.
* @param repeat    The selector will be executed (repeat + 1) times, you can use CC_REPEAT_FOREVER for tick infinitely.
* @param delay     The amount of time that the first tick will wait before execution.
* @param key       The key of the lambda function. To be used if you want to unschedule it.
* @lua NA
*/
void schedule(const std::function<void(float)>& callback, float interval, unsigned int repeat, float delay, const std::string &key);
注:我们想要定时器第一次执行时等待0秒,会把第四个参数delay 设为0,但会发现效果并不是我们想的那样(若第四个参数delay 设为0 该函数的第一次执行是在等待interval之后),第一次执行时等待时间只能趋近与0不能等于0
Node::schedule->Scheduler::schedule->initWithCallback->setupTimerWithInterval

void Timer::setupTimerWithInterval(float seconds, unsigned int repeat, float delay)
{
        _elapsed = -1;
        _interval = seconds;
        _delay = delay;
        _useDelay = (_delay > 0.0f) ? true : false;
        _repeat = repeat;
        _runForever = (_repeat == CC_REPEAT_FOREVER) ? true : false;
}

查看源码发现有判断只有当 我们传入的_delay > 0.0f 才会使用我们传入的值。