SFML community forums
Help => Window => Topic started by: Prominence256 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:
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?
-
You need to check for movement larger than a certain amount at once to filter out small jitters just like real screensavers do.
-
I tried using an IntRect and checking if it contains the current mouse coordinates but that didn't work. Here's what I did:
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;
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.
-
Can you show your complete code?
-
You should store OldMouseX and OldMouseY and compare against them.
-
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.