SFML Window 当鼠标离开 window 时自行关闭
SFML Window closes by itself when mouse goes outside of window
我的 SFML 应用程序按预期构建和运行,但是当鼠标 exit/enter 左 window 边框上的 window 时,它会意外关闭。
我怎样才能让这个错误停止发生?我不希望 window 关闭,除非我在代码中调用它。
Visual Studio 2019
SFML-2.5.1
(我想我下载的版本是:Visual C++ 15 (2017) - 32-bit)
这是我 运行 产生上述错误的最简单的代码示例:
#include "SFML-2.5.1/include/SFML/Graphics.hpp"
#include <iostream>
#include <vector>
#include <string>
using std::cout;
using std::endl;
using std::vector;
using std::endl;
using std::string;
sf::Vector2f window_size(800, 600);
sf::VideoMode video_mode(window_size.x, window_size.y);
sf::RenderWindow window(video_mode, "Hello");
int main() {
while (window.isOpen()) {
//Deal with input and update program
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed
|| event.key.code == sf::Keyboard::Escape) {
window.close();
}
}
//Draw things on screen
window.clear(sf::Color::White);
//Draw things here, not nothing right now
window.display();
}
}
sf::Event
组织为tagged union,其中type
成员为tag,活跃成员依赖于tag。
key
成员仅在 type
是其中一种键盘事件类型(sf::Event::KeyPressed
或 sf::Event::KeyReleased
)时有效。
检查不活跃的联合成员是未定义的行为。实际上,发生的事情可能类似于以下内容。发生了一些其他事件,其中一个成员在数值上等于 sf::Keyboard::Escape
,并且在物理上与 key.code
共享 space。该程序正在访问该成员并将其错误地解释为 key.code
.
相关文档:
我的 SFML 应用程序按预期构建和运行,但是当鼠标 exit/enter 左 window 边框上的 window 时,它会意外关闭。
我怎样才能让这个错误停止发生?我不希望 window 关闭,除非我在代码中调用它。
Visual Studio 2019
SFML-2.5.1 (我想我下载的版本是:Visual C++ 15 (2017) - 32-bit)
这是我 运行 产生上述错误的最简单的代码示例:
#include "SFML-2.5.1/include/SFML/Graphics.hpp"
#include <iostream>
#include <vector>
#include <string>
using std::cout;
using std::endl;
using std::vector;
using std::endl;
using std::string;
sf::Vector2f window_size(800, 600);
sf::VideoMode video_mode(window_size.x, window_size.y);
sf::RenderWindow window(video_mode, "Hello");
int main() {
while (window.isOpen()) {
//Deal with input and update program
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed
|| event.key.code == sf::Keyboard::Escape) {
window.close();
}
}
//Draw things on screen
window.clear(sf::Color::White);
//Draw things here, not nothing right now
window.display();
}
}
sf::Event
组织为tagged union,其中type
成员为tag,活跃成员依赖于tag。
key
成员仅在 type
是其中一种键盘事件类型(sf::Event::KeyPressed
或 sf::Event::KeyReleased
)时有效。
检查不活跃的联合成员是未定义的行为。实际上,发生的事情可能类似于以下内容。发生了一些其他事件,其中一个成员在数值上等于 sf::Keyboard::Escape
,并且在物理上与 key.code
共享 space。该程序正在访问该成员并将其错误地解释为 key.code
.
相关文档: