SFML community forums

Help => Window => Topic started by: Makuto on October 24, 2012, 02:23:36 am

Title: Prevent Clicking Offscreen
Post by: Makuto on October 24, 2012, 02:23:36 am
How do I make it so the user cannot click off the screen? I have an action TDS and the play testers became frustrated when the window was buried after they clicked off screen while aiming.
Title: Re: Prevent Clicking Offscreen
Post by: FRex on October 24, 2012, 03:55:31 am
Run in fullscreen?
Have last mouse position saved and keep checking if mouse left the window and if it did then get it to last valid position?
But I really recommend fullscreen since the purpose of the window is that you can click somewhere to get it to unfocus, hide, ect.
Title: Re: Prevent Clicking Offscreen
Post by: Makuto on October 24, 2012, 06:09:50 am
What if I paused the game if the window went out of focus? If so, how do I check for that in SFML?
Title: Re: Prevent Clicking Offscreen
Post by: masskiller on October 24, 2012, 06:30:47 am
if (event.type == sf::Event::LostFocus)
    myGame.pause();

if (event.type == sf::Event::GainedFocus)
    myGame.resume();

That should be all it takes.

http://www.sfml-dev.org/tutorials/2.0/window-events.php (http://www.sfml-dev.org/tutorials/2.0/window-events.php)
Title: AW: Prevent Clicking Offscreen
Post by: eXpl0it3r on October 24, 2012, 09:04:05 am
Unfortunatly there's no way in really locking the mouse in. See the discussion here (http://en.sfml-dev.org/forums/index.php?topic=9426.0).
Title: Re: Prevent Clicking Offscreen
Post by: Makuto on October 24, 2012, 03:07:13 pm
This:
sf::Event event;
        while (win.getBase()->GetEvent(event))
        {
            if (event.Type==sf::Event::LostFocus) return false;
            if (event.Type==sf::Event::GainedFocus) return true;
        }
 
Doesn't appear to do anything (there are never any events). What is the reason for this? (Note that I've abstracted the RenderWindow into my own window class for easy graphics lib switching)
Title: AW: Prevent Clicking Offscreen
Post by: eXpl0it3r on October 24, 2012, 03:23:44 pm
What OS & compiler are you using then?
The events should be triggered if the window loses focus or have you integrated it with Qt/wxWidget or similar?
Title: Re: Prevent Clicking Offscreen
Post by: Makuto on October 25, 2012, 04:25:45 am
I'm using Ubuntu Linux and compiling with G++. I receive other events (but not focus events) if I put a window->Display() before the listener....