cocos2d-x快速加按钮

前端之家收集整理的这篇文章主要介绍了cocos2d-x快速加按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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();
}
原文链接:https://www.f2er.com/cocos2dx/338464.html

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