Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法在cocos2dx中显示菜单菜单图像_C++_Cocos2d X_Cocos2d X 3.0 - Fatal编程技术网

C++ 无法在cocos2dx中显示菜单菜单图像

C++ 无法在cocos2dx中显示菜单菜单图像,c++,cocos2d-x,cocos2d-x-3.0,C++,Cocos2d X,Cocos2d X 3.0,目前,我正在尝试在cocos2dx中显示menumenuitemage,但它没有显示。精灵显示正常。我在谷歌上搜索了一下,但没有找到解决办法。我想从你那里得到一些提示或例子 bool GameLayer::init(int level) { if (!Layer::init()) return false; auto moreButton = MenuItemImage::create("more.png","more.png",[](Ref*sender){}

目前,我正在尝试在cocos2dx中显示menumenuitemage,但它没有显示。精灵显示正常。我在谷歌上搜索了一下,但没有找到解决办法。我想从你那里得到一些提示或例子

bool GameLayer::init(int level)
{
    if (!Layer::init())
        return false;

    auto moreButton = MenuItemImage::create("more.png","more.png",[](Ref*sender){});
    moreButton->setPosition(Vec2(WINSIZE.width /2.0,WINSIZE.height / 2.0));

    this->addChild(moreButton, ZOrder::Enemy);

    auto menu = Menu::create(moreButton, NULL);
    this->addChild(menu);
    menu->setPosition(WINSIZE.width / 2.0, WINSIZE.height / 2.0);

    initBackground(); 
    return true;
}


void GameLayer::initBackground()
{
    auto bgForCharacter = Sprite::create("Background1.png");
    bgForCharacter->setAnchorPoint(Point(0, 1));
    bgForCharacter->setPosition(Point(0, WINSIZE.height));
    addChild(bgForCharacter, ZOrder::BgForCharacter);

    auto bgForPuzzle = Sprite::create("Background2.png");
    bgForPuzzle->setAnchorPoint(Point::ZERO);
    bgForPuzzle->setPosition(Point::ZERO);
    addChild(bgForPuzzle, ZOrder::BgForP);
    //TODO
}
以下内容在header类中

 enum ZOrder
    {
        BgForCharacter = 0,
        BgForPuzzle,
        Enemy,
        EnemyHp,
        Char,
        CharHp,
        Ball,
        Level,
        Result,
    };
您可以假定菜单是不同类型菜单项的容器或父菜单项。无需设置菜单项的位置如果您有单个菜单项,请设置其父菜单的位置

不向场景或层添加菜单项,只需传入菜单的创建方法。当您传入create方法时,它将作为子菜单添加到该菜单中

如果菜单中有多个菜单项,则需要设置每个菜单项的位置


MenuItem位置与其父菜单相对应,因此根据您的代码,您将菜单设置在屏幕中央,然后将相同的偏移量设置到其子菜单,以便右上角的MenuItem可能不可见。

WINSIZE的值是什么?定义WINSIZE控制器::getInstance->getWinSizeI已更新代码。菜单没有显示。可能是因为我添加到其他精灵的ZOrder?您的代码在auto menu=menu::createmoreButton,NULL;因为已经添加了更多按钮。无法再次添加。您正在使用哪个版本的cocos2d-x?我使用的是v3.15
bool GameLayer::init(int level)
{
    if (!Layer::init())
        return false;

    auto moreButton = MenuItemImage::create("more.png","more.png",[](Ref*sender){});

    auto menu = Menu::create(moreButton, NULL);        
    menu->setPosition(WINSIZE.width / 2.0, WINSIZE.height / 2.0);
    this->addChild(menu);

    initBackground(); 
    return true;
}