首页 > 解决方案 > SFML 2.0 - 窗口出现后立即关闭

问题描述

窗口出现后立即关闭,即使它应该等待关闭事件。
主.h:

#include <SFML/Graphics.hpp>
#include <iostream>
#include "window.h"
int main()
{
    window::window mainwindow;
    mainwindow.createwindow(800, 600);
    while(mainwindow.window.pollEvent(mainwindow.events)){
        if (mainwindow.events.type == sf::Event::Closed){
            mainwindow.window.close();
        }
    }
    return 0;
}

窗口.h:

#include <SFML/Graphics.hpp>
#include <iostream>
namespace window{
class window{
    public:
        sf::Window window;
        sf::Event events;
        void createwindow(int resx, int resy){
            window.create(sf::VideoMode(resx, resy), "MainWindow", sf::Style::Default);
            }
        };
}

该代码基于此 SFML 教程:https://www.sfml-dev.org/tutorials/2.5/window-window.php
我正在使用 SMFL 2-2.5.1-23.83,IDE 为 code::blocks 20.03。感谢所有帮助

标签: c++codeblockssfml

解决方案


推荐阅读