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

Author Topic: Screen Savers and Event::MouseMoved  (Read 2878 times)

0 Members and 1 Guest are viewing this topic.

Prominence256

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://GameMakerStation.110mb.com/
Screen Savers and Event::MouseMoved
« on: January 26, 2011, 02:42:50 am »
I'm trying to make a simple Windows screen saver. My only issue is closing it when the mouse moves. This is my code:
Code: [Select]
case Event::MouseMoved:
app.Close();
break;
The problem is that this closes the window as soon as it opens. Is there any way to fix this?

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Screen Savers and Event::MouseMoved
« Reply #1 on: January 26, 2011, 03:15:03 am »
You need to check for movement larger than a certain amount at once to filter out small jitters just like real screensavers do.

Prominence256

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://GameMakerStation.110mb.com/
Screen Savers and Event::MouseMoved
« Reply #2 on: January 26, 2011, 04:08:04 am »
I tried using an IntRect and checking if it contains the current mouse coordinates but that didn't work. Here's what I did:
Code: [Select]
IntRect box;
box.Left   = app.GetInput().GetMouseX() - 16;
box.Right  = app.GetInput().GetMouseX() + 16;
box.Top    = app.GetInput().GetMouseY() - 16;
box.Bottom = app.GetInput().GetMouseY() + 16;
Code: [Select]
case Event::MouseMoved:
int mx = app.GetInput().GetMouseX();
int my = app.GetInput().GetMouseY();
if (!box.Contains(mx, my))
app.Close();
break;
And it still immediately closed.

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
Screen Savers and Event::MouseMoved
« Reply #3 on: January 26, 2011, 07:21:03 am »
Can you show your complete code?

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Screen Savers and Event::MouseMoved
« Reply #4 on: January 26, 2011, 12:31:50 pm »
You should store OldMouseX and OldMouseY and compare against them.

Prominence256

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://GameMakerStation.110mb.com/
Screen Savers and Event::MouseMoved
« Reply #5 on: January 26, 2011, 10:29:54 pm »
I found the problem. The issue was that OldMouseX and Y were only assigned values once, and that time happened to be before the window had finished loading so they were always set to 0. The odds of you actually putting the mouse in the top left corner are pretty low, that's why it always closed.

 

anything