我创建了一个例子,其中我有2个窗口同时打开,window1无法处理事件,而window2是打开的。我改变了当前窗口的颜色以说明其工作情况(如果我移动鼠标,则window1打开,window2变得更绿,更环保)。但即使window1在窗口2打开时无法处理事件,我仍然无法改变window1的位置。我希望无法做到这一点。
#include <SFML/OpenGL.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
using namespace std;
sf::Event event;
int main()
{
sf::RenderWindow window1(sf::VideoMode(600, 600), "Window1");
sf::RenderWindow window2(sf::VideoMode(300, 300), "Window2");
int r=0,g=0;
while (window1.isOpen())
{
if(window2.isOpen()==false)
while (window1.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window1.close();
r=(r+1)%255;
}
else
{
while (window2.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window2.close();
g=(g+1)%255;
}
}
window1.clear(sf::Color(r,0,0));
window1.display();
window2.clear(sf::Color(0,g,0));
window2.display();
}
return 0;
}
我该怎么做?
答案 0 :(得分:0)
SFML中没有直接的功能(虽然我希望它可以使用特定于平台的代码),但有几种解决方法: