Node的定时器

来源:互联网 发布:算法导论 原版 编辑:程序博客网 时间:2024/06/12 19:16

默认定时器scheduleUpdate()

    该定时器默认刷新次数与屏幕刷新频率有关。如频率为60帧每秒,那么scheduleUpdate每秒执行60次刷新。

    scheduleUpdate其对应的刷新函数体为update(),即每一帧会执行一次update()函数。

    相关操作如下:

    //开启默认定时器。刷新间隔为一帧。

    void scheduleUpdate();

    void scheduleUpdateWithPriority(int priority); //给予优先级prioritypriority越小,优先级越高

virtual void update(float delta); //updatescheduleUpdate定时器的刷新函数体.

使用方法:

this->scheduleUpdate();或者

    void HelloWorld::update(float delta)

    {

        CCSprite* sp = (CCSprite*)this->getChildByTag(100); //获取tag=100的精灵

        sp->setPosition( sp->getPosition() + ccp(1,0) );    //每帧移动1

    }

自定义定时器schedule()

    该定时器可以自定义指定的刷新函数体、刷新函数体的次数、刷新频率、以及开始刷新的时间。

    函数体不一定为update(),可以自己定义。

一次调用定时器scheduleOnce()