SFML事件不显示
SFML Events not displaying?
我的SFML程序中的Events功能不起作用。main()的一般结构如下所示。我想注册最后按下的键并相应地切换屏幕。我知道下面将要求键保持按下,但即使这样做作为测试也不起作用。
我遗漏了什么语法?我在论坛上看到的教程和示例代码使它看起来像下面一样简单。我曾见过在按键上使用开关,但这似乎更多地用于电子游戏中的即时响应。
int main()
{
srand (time(NULL));
sf::RenderWindow window(sf::VideoMode(SIZE, SIZE), "Curling Party");
window.setFramerateLimit(30);
...
while(window.isOpen())
{
sf::Event event;
window.pollEvent(event);
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Q)
{
window.close();
break;
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::R)
{
...
window.display();
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::B)
{
...
window.display();
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
{
...
}
window.clear(sf::Color::White);
window.draw(house[0]);
window.draw(house[1]);
window.draw(house[2]);
window.draw(house[3]);
window.display();
}
return 0;
}
window.pollEvent(event)
应该在while循环中,如文档所述:
人们经常犯的一个错误是忘记事件循环,仅仅是因为他们还不关心处理事件(他们使用实时输入代替)。如果没有事件循环,窗口将变得无响应。重要的是要注意,事件循环有两个角色:除了向用户提供事件之外,它还为窗口提供了处理其内部事件的机会,这是必需的,以便它可以对移动或调整用户操作做出反应。
虽然window.display()
应该只在窗口循环结束时调用,但您不需要在每个键被按下后显示窗口。
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- Android NDK传感器向事件队列报告奇怪的间隔
- 程序崩溃并显示"std::out_of_range"错误
- 从文本文件中读取时钟时间和事件时间并进行处理
- WMI检测进程创建事件-c++
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- Qt:事件过滤器在显示 QCompleter 时不接收按键
- 开关(事件类型)不工作和计时器不显示
- SDL视频显示窗口:如何连接窗口关闭事件回调
- QT在事件上显示不同的场景
- 显示 QT 上下文菜单时没有键发布事件
- 显示事件后的Qt4 qwidget
- X11 MotionNotify 事件未显示在单独的共享库中?
- Qt:隐藏然后显示QQuickView防止未来的鼠标事件
- SFML事件不显示