【问题标题】:SFML RenderWindow wont open in splashscreenSFML RenderWindow 不会在闪屏中打开
【发布时间】:2014-01-03 13:10:55
【问题描述】:

我试图在 SFML 2.1 中显示 5 秒的启动画面,显示显示在主游戏循环中,但在 init 方法中,没有显示,图标在 Dock 上显示 5 秒,但没有窗口.. .

int initGame(){
    gameState = GAME_LOADING;
    // Create the main window
    window.create(mainVideoMode, "SFML Window", sf::Style::Default);
    // Set the Icon
    if (!icon.loadFromFile(resourcePath() + "icon.png")) {
        gameState = GAME_EXIT;
    }
    sf::Texture texture;
    if (!texture.loadFromFile(resourcePath() + "splashscreen.png"))
    {
        gameState = GAME_EXIT;
    }
    window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
    sf::Sprite sprite(texture);

    window.clear();
    window.draw(sprite);
    window.display();

    // Create a graphical text to display
    /*if (!font.loadFromFile(resourcePath() + "sansation.ttf")) {         If Needed
        return EXIT_FAILURE;
    }*/

    sf::sleep(sf::seconds(5));
    gameState = GAME_PLAYING;
    return 1;
}

【问题讨论】:

    标签: c++ game-engine sfml


    【解决方案1】:

    您需要一个基本的游戏循环,并且需要用适合游戏的计时器构造替换您的睡眠呼叫。请查看here 以获得详细答案。

    无论您的游戏中发生什么,都可能永远不会影响输入/更新/渲染的游戏循环周期。如果您不想接受输入并且 5 秒内不更新,那很好。但是您需要该循环才能运行。

    伪代码,因为我手头没有编译器:

    variable timePassed = 0 seconds;
    
    while(window is open && timePassed < 5 seconds)
    {
        timePassed += the time that passed since the last loop
    
        window.clear();
        window.draw(splashscreen);
        window.display();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      相关资源
      最近更新 更多