1
0
Fork 0

main: Clean up, handle resize

Handle window resizes by resizing the view frame as well.

Clean up the event handling to allow interleaving other code between
different checks.
Remove early first frame, handle it like the others.
This commit is contained in:
Teo-CD 2024-01-24 23:09:59 +00:00
parent b47052aa4d
commit 4a95664342

View file

@ -14,8 +14,7 @@ int main()
std::cout << world << std::endl;
sf::RenderWindow window(sf::VideoMode(800,600),"Da raycasting");
world.render(window);
window.display();
sf::RenderWindow window(sf::VideoMode(1000,1000),"Da raycasting");
sf::Event event{};
sf::Clock frameTime;
@ -23,9 +22,19 @@ int main()
{
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
if (event.type == sf::Event::Closed) {
window.close();
else if (event.type == sf::Event::KeyPressed) {
continue;
}
if (event.type == sf::Event::Resized) {
// Keep the view area fit to the window.
sf::FloatRect newView(0, 0,
static_cast<float>(event.size.width),
static_cast<float>(event.size.height));
window.setView(sf::View(newView));
continue;
}
if (event.type == sf::Event::KeyPressed) {
switch (event.key.code) {
case sf::Keyboard::Key::Escape:
window.close();