游戏菜单未在释放模式下关闭,但在调试模式下工作

时间:2013-03-05 05:48:19

标签: c++ visual-studio-2010 sfml

我正在使用VS 2010.我的游戏内菜单没有在发布模式下关闭。它在调试模式下工作。 这是我的代码尽可能多地删除了无关的代码,希望你仍然可以看到它的作用。

应该发生的是当按下ESC键时,菜单显示然后用户单击一个按钮并返回一个int,告诉Game类该做什么。单击“退出”时,它可以正常工作。但是,当我单击其他任何内容时,将执行正确的操作,仅关闭闪存菜单,然后重新启动。我不知道为什么它会保持开放。如果我在菜单启动时按下按钮(例如ESC),则菜单会按照预期关闭。

Game::GameLoop
{ //etc code &Update and Draw Functions
    if(currentEvent.Type == sf::Event::KeyPressed && currentEvent.Key.Code == sf::Key::Escape)
    {
        ShowGameMenu();
    }
    //Code
    //Display() - clear buffer to the screen
}

void Game::ShowGameMenu()
{
    int bMenu = 0;
    bMenu = menu.Show(m_MainWindow);

    switch (bMenu) {
    case 1: //gameOn
        m_GameState = dlb::Playing;
        break;//etc cases that aren't the problem
    }
}

int Menu::Show(sf::RenderWindow& window)
{//Various menuState code that isn't the problem removed - This passes the returnCode back to game
    int code = 0;
    code = MainMenu(window);
    return code;
}

//returns 1-gameOn, 2-SplashScreen, 0-close, 3-restartLvl, 4-restartGame, 5-option,
int Menu::MainMenu(sf::RenderWindow& window)
{
    int returnCode = -1;
    bool running = true;
    sprite.SetPosition(center);

    sf::Event currentEvent;

    while (running)
    {
        window.GetEvent(currentEvent);

        Draw(window); //Displays the menu on top of game window

        if(currentEvent.Type == sf::Event::KeyPressed && currentEvent.Key.Code == sf::Key::Escape) //This works too
        {
            returnCode = 1;
            running = false;
        }

        if (currentEvent.Type == sf::Event::MouseButtonReleased && currentEvent.MouseButton.Button == sf::Mouse::Left)
        {
            sf::Vector2f mouse = sf::Vector2f((float)currentEvent.MouseButton.X, (float)currentEvent.MouseButton.Y);

            while ((*currItr)->IsEnd() != true)
            {
                if ((*currItr)->isClicked(mouse))
                {
                    //returns 1-gameOn, 2-SplashScreen, 0-close, 3-restartLvl, 4-restartGame, 5-option,
                    switch ((*currItr)->GetType())
                    {
                    case dlb::Exit:
                        returnCode = 0;
                        break;
                    case dlb::ReturnGame:
                        returnCode = 1;
                        break;
                        //various cases removed here because they matter not
                    }
                    running = false;
                    break;
                }
                else
                {
                    ++currItr;
                }
            }
        }
    }

    return returnCode;
}

我很抱歉有这么多代码,我试图删除所有无法解释发生了什么的内容。如果您需要更多,我可以发布更多代码并尝试解释我不明确的任何内容。任何想法都会在这一点上受到赞赏,我已经尝试了所有我能想到的东西,并且除了打破它并且不得不修复它之外什么都没做。

[UPDATE]

它返回正确的代码,如果我选择重启(冒险),退出或SplashScreen,我会得到正确的行为。当我返回1继续游戏时,菜单会闪烁关闭然后重新打开。但只有当我点击时才会这样。如果我按下代码中任何其他位置的任何其他键或按钮,它将关闭。 (例如,在点击之前按住向上箭头移动玩家,它将正确关闭菜单并移动角色。) 我上下搜索了我的代码,并没有在任何地方看到任何未初始化的变量。 我愿意尝试任何事情;我绝对亏本。

0 个答案:

没有答案
相关问题