layer-> schedule()不起作用

时间:2013-03-27 09:51:41

标签: cocos2d-iphone cocos2d-x

void HelloWorld::startMovingBackground() {

    CCLog("startMovingBackground...");

    if ( isLeftPressed && isRightPressed ) {
        return;
    }

    CCLog("schedule...");        // OK.......................

    this->schedule(schedule_selector(HelloWorld::moveBackground));
}

void HelloWorld::moveBackground(float f) {

    CCLog("moveBackground %f", f);       // NO....................

    // Do move background...
}

但是, 不调用moveBackground函数。帮帮我...

=============================================== ===========

代码(初始化“HelloScene”)

CCScene* HelloWorld::scene() {
    CCScene * scene = NULL;
    do {
        scene = CCScene::create();
        CC_BREAK_IF(! scene);
        HelloWorld *layer = HelloWorld::create();
        CC_BREAK_IF(! layer);
        scene->addChild(layer);
    } while (0);
    return scene;
}

bool HelloWorld::init()
{
    bool bRet = false;
    do {
        CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) );

        this->setTouchEnabled(true);

        winSize = CCDirector::sharedDirector()->getWinSize();

        this->setTouchEnabled(true);

        this->createBackgroundParallax();

        this->createArrowButtons();

        bRet = true;
    } while (0);

    return bRet;
} 

2 个答案:

答案 0 :(得分:1)

如果您调用onEnterscheduleUpdate()可能无效。请尝试以下操作:

CCDirector::sharedDirector()->getScheduler()->scheduleUpdateForTarget(this,0,false);

CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(NewGame::update),this,0.1,false);

答案 1 :(得分:-2)

你错过了

中的争论
this->schedule( selector, time_interval);

如果我没记错了,默认值为0,永远不会被调用。