cocos2d-x定时器

前端之家收集整理的这篇文章主要介绍了cocos2d-x定时器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

xxx.h文件

void MoveX(float dt);
    int count;

xxx.cpp文件

//1.循环执行定时器:要调用函数,每隔1秒调用一次。
    count = 0;
    //this->schedule(schedule_selector(MainMap::MoveX),1.0f);

    //2.一次性定时器:要调用函数,5秒后调用一次。
    this->scheduleOnce(schedule_selector(MainMap::MoveX),5.0f);

    //3.停止所有定时器
    //this->unscheduleAllSelectors();

void MainMap::MoveX(float dt)
{
    CCLOG("hello!");

    if (count<15) {
        count = count + 1;
    }else{
        //停止定时器
        this->unschedule(schedule_selector(MainMap::MoveX));
    }

}
原文链接:https://www.f2er.com/cocos2dx/340504.html

猜你在找的Cocos2d-x相关文章