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:
parent
804f0272f8
commit
7fe17df587
1 changed files with 14 additions and 5 deletions
19
main.cpp
19
main.cpp
|
@ -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)
|
||||
window.close();
|
||||
else if (event.type == sf::Event::KeyPressed) {
|
||||
if (event.type == sf::Event::Closed) {
|
||||
window.close();
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue