3.x CC_CALLBACK_*系列和2.x对比

<1>CC_CALLBACK_0

if (m_touchSp) {
        m_touchSp->runAction(Sequence::create(ScaleTo::create(time, 1), MoveTo::create(time, Vec2(m_destSp->getPositionX(), m_destSp->getPositionY() + spWidth)), ScaleTo::create(time, 1), CallFunc::create(CC_CALLBACK_0(GameScene::removeTouchSp, this)), NULL));
    }

void GameScene::removeTouchSp()
{
    if (m_touchSp) {
        m_touchSp->removeFromParent();
        m_touchSp = NULL;
    }
}

<2>CC_CALLBACK_1

animationSp->runAction(Sequence::create(MoveTo::create(time, Vec2(endPosition.x, endPosition.y - 15)), MoveTo::create(BACK_TIME, Vec2(endPosition.x, endPosition.y)), CallFuncN::create(CC_CALLBACK_1(GameScene::setSpIsTouchEnable, this)),NULL));

void GameScene::setSpIsTouchEnable(Node *node)
{
    AnimationSprite *sp = (AnimationSprite *)node;
    if (!sp) {
        return;
    }
    
    BubbleSprite *bubbleSp = m_bubbleMatrix[sp->getRow() * m_width + sp->getCol()];
    if (bubbleSp) {
        return;
    }
    
    CloudSprite *cloudSp = m_cloudMatrix[sp->getRow() * m_width + sp->getCol()];
    if (cloudSp) {
        return;
    }
    
    sp->setIsTouchEable(true);
}

<3>CC_CALLBACK_2

//注册触摸事件
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
    touchListener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this);
    touchListener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
    
    //键盘事件
    auto keyDiapatcher = Director::getInstance()->getEventDispatcher();
    EventListenerKeyboard *keyboardListener = EventListenerKeyboard::create();
    keyboardListener->onKeyPressed = CC_CALLBACK_2(GameScene::onKeyPressed, this);
    keyboardListener->onKeyReleased = CC_CALLBACK_2(GameScene::onKeyReleased, this);
    keyDiapatcher->addEventListenerWithSceneGraphPriority(keyboardListener, this);

<4>bind

 _textLimitstep->runAction(Sequence::create(ScaleTo::create(0.1, 1.4), CallFunc::create(std::bind(&GameScene::setProlongStep, this)), ScaleTo::create(0.05, 1), NULL));

this->runAction(Sequence::create(DelayTime::create(0.15f), CallFunc::create(std::bind(&GameScene::afterAchieveGoal, this, 0)),  NULL));


你可能感兴趣的:(3.x CC_CALLBACK_*系列和2.x对比)