Hi, I create a feature that if the user clicks the menu, a window pops out. I'm able to display the pop window but not close it.
class PopWindow {
private:
sf::RenderWindow popWin;
sf::Color popWinColor = sf::Color(50, 50, 50);
public:
// Default constructor
PopWindow();
// While pop is Open
int winOpen();
};
#include "PopWindow.h"
PopWindow::PopWindow() {
popWin.create(sf::VideoMode(500, 500), "Pop Window");
}
int PopWindow::winOpen() {
sf::Event popWinEvent{};
while (popWin.isOpen()) {
while (popWin.pollEvent(popWinEvent)) {
if (popWinEvent.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::F2)) {
popWin.close();
}
popWin.clear(popWinColor);
popWin.display();
}
}
return 0;
}
The weird thing is if I declare a PopWindow object and call object.winOpen() in the main class, everything works fine, however, if the object is declared in one of other classes, I can only open a new window but not close it.
How to handle events for multiple windows?
Thanks for your help!