Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Clicking in Window Doesn't Give Focus  (Read 2943 times)

0 Members and 1 Guest are viewing this topic.

malkierian

  • Newbie
  • *
  • Posts: 39
    • View Profile
Clicking in Window Doesn't Give Focus
« on: October 17, 2013, 03:53:30 am »
So I just started developing games using SFML, and I've got a major problem.  I have my main loop set up thusly:

while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
                        if (event.type == sf::Event::LostFocus)
                                paused = true;
                        if (event.type == sf::Event::GainedFocus)
                                paused = false;
        }
                if(paused)
                        continue;
                ship.resetDirections();
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        ship.direction[3] = true;
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        ship.direction[1] = true;
                }

                ship.updatePosition();

        window.clear();
        window.draw(ship);
        window.display();
    }
Now, you'll notice, in the polling loop, I have a pausing thing going on.  Losing focus pauses the game, gaining focus resumes the game.  Pretty basic pausing system for now (I'll make a pause menu eventually).  But, when I click inside the window frame (anywhere but the title bar, or the outline around the black that the background currently is), the window isn't actually getting focus.  It doesn't, unless I actually go and click the window frame, or click the program's icon on my start bar (Windows 7).  I'm using VS2012, and have it going through the System package to maintain compatibility.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Clicking in Window Doesn't Give Focus
« Reply #1 on: October 17, 2013, 04:42:04 am »
It's a bug in SFML 2.1, but it got already fixed in the current Git version. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

malkierian

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Clicking in Window Doesn't Give Focus
« Reply #2 on: October 17, 2013, 05:12:54 am »
Ah, I see.  And there just happens to be a link to some dev builds in your sig!  How convenient :D

TheRabbit

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Clicking in Window Doesn't Give Focus
« Reply #3 on: November 02, 2013, 10:56:21 pm »
Is there a way that I can fix this using an sf::Event? Or is the only way around it to use a dev build?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Clicking in Window Doesn't Give Focus
« Reply #4 on: November 02, 2013, 10:59:17 pm »
Is there a way that I can fix this using an sf::Event? Or is the only way around it to use a dev build?

Just build SFML yourself, after all it would be very beneficial to you if you learned how to do it.  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor