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

Author Topic: Prevent Clicking Offscreen  (Read 2952 times)

0 Members and 1 Guest are viewing this topic.

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Prevent Clicking Offscreen
« 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.
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Prevent Clicking Offscreen
« Reply #1 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.
Back to C++ gamedev with SFML in May 2023

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Re: Prevent Clicking Offscreen
« Reply #2 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?
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Prevent Clicking Offscreen
« Reply #3 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
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Prevent Clicking Offscreen
« Reply #4 on: October 24, 2012, 09:04:05 am »
Unfortunatly there's no way in really locking the mouse in. See the discussion here.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Re: Prevent Clicking Offscreen
« Reply #5 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)
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Prevent Clicking Offscreen
« Reply #6 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Re: Prevent Clicking Offscreen
« Reply #7 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....
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?