当前位置 : 主页 > 手机开发 > 其它 >

cocos2d-x快速加按钮

来源:互联网 收集:自由互联 发布时间:2021-06-13
const int TAG_EXIT = 10000 ; const int TO_MY_HALL = 10001 ; const int RESTART = 10002 ; void GameResult::addButton( const char * name, int tag, float x, float y, const char * txt){ auto b = MenuItemImage::create(name, name, this , menu_sele
const int TAG_EXIT = 10000;
const int TO_MY_HALL = 10001;
const int RESTART = 10002;
void GameResult::addButton(const char* name, int tag, float x, float y, const char* txt)
{
    auto b = MenuItemImage::create(name, name, this, menu_selector(GameResult::cb));

    TI()->setPos(b, x, y);
    b->setTag(tag);
    auto m = Menu::create(b, NULL);
    m->setPosition(Vec2::ZERO);
    addChild(m, 100);

    auto _txt = Label::createWithSystemFont(txt, "Arial", 30);
    b->addChild(_txt);
    _txt->setPosition(b->getContentSize().width/2, b->getContentSize().height/2);

}

void GameResult::cb(Ref* obj)
{
    Node* node = dynamic_cast<Node*>(obj);
    switch (node->getTag())
    {
        case TAG_EXIT:

            break;

        case TO_MY_HALL:

            break;
        case RESTART:

            break;
        default:
            break;
    }

    this->setVisible(false);
    ((GameMenu *)this->getParent())->onResultHide();
}
网友评论