cocos跨类调用按钮事件

//在TaskScene定义一个按钮事件

void TaskScene::GotoFightScene(const Widget::ccWidgetClickCallback& callback)
{
    Button* fightBtn = rootNode->getChildByName<Button*>("Button_1");
    fightBtn->addClickEventListener(callback);
}

//在TailorDesign类中调用,功能是在该类中点击某个按钮,调用该函数,显示其他场景

void TailorDesign::showFightScene()
{
    TaskScene *taskS = TaskScene::create();
    addChild(taskS);
    taskS->GotoFightScene([&](Ref* ref)
    {
        addChild(FightScene::create());
    });

}

猜你喜欢

转载自blog.csdn.net/piyixia/article/details/88675816