cocos2d-x定時器

###
可以让类继承于 CCNode 产生这个定时器,如果还没有作用,那么可以在初始化的时候加上:
    CCNode::onEnter();

###
    scheduleUpdate();

void schedule (SEL_SCHEDULE selector)
     schedules a selector.
void schedule (SEL_SCHEDULE selector, ccTime interval)
     schedules a custom selector with an interval time in seconds.
void unschedule (SEL_SCHEDULE selector)
     unschedules a custom selector.
void unscheduleAllSelectors (void)
     unschedule all scheduled selectors: custom selectors, and the 'update' selector.


###
    CCScheduler *default_scheduler = CCDirector::sharedDirector()->getScheduler();
    default_scheduler->scheduleUpdateForTarget(this, 0, false);
    default_scheduler->unscheduleUpdateForTarget(this);


### 定時執行

    //每一秒執行 GameLayer 的函數 Step(ccTime dt)
    this->schedule(schedule_selector(GameLayer::Step), 1.0f);

void GameLayer::Step(ccTime dt)
{
}

### 延時執行
    //延時5秒執行函數
    this->schedule(schedule_selector(GameLayer::Step), 5.0f);

void GameLayer::Step(ccTime dt)
{
    this->unschedule(schedule_selector(GameLayer::Step));
}

    CCScheduler *default_scheduler = CCDirector::sharedDirector()->getScheduler();
    default_scheduler->unscheduleUpdateForTarget(this);

你可能感兴趣的:(cocos2d-x)