SFML community forums

Help => Window => Topic started by: Brendon on September 25, 2011, 08:37:04 pm

Title: SFML2 - desktop mouse vs. renderwindow mouse [SOLVED]
Post by: Brendon on September 25, 2011, 08:37:04 pm
I'm currently updating my project to the latest SFML2. In the new input system, I noticed my desktop mouse and renderwindow mouse are located at two different locations:

(http://blendogames.com/dev/sfml2mouse.jpg)

Moving one cursor also moves the other. Cosmetically, I don't mind. But functionally, I have a problem in that left-clicking will de-focus the renderwindow and select the underlying desktop.

Has anyone experienced a similar problem, or does my input code need some massaging?
Title: SFML2 - desktop mouse vs. renderwindow mouse [SOLVED]
Post by: Hiura on September 25, 2011, 08:55:56 pm
Are you using sf::Mouse::SetPosition ?

If so, make sure you are using sf::Mouse::SetPosition(const Vector2i& position, const Window& relativeTo) and not sf::Mouse::SetPosition(const Vector2i& position).
Title: SFML2 - desktop mouse vs. renderwindow mouse [SOLVED]
Post by: Groogy on September 25, 2011, 08:56:05 pm
Hmm the input system has had a pretty big make over if you missed it. Look at sf::Mouse for more information about getting real-time mouse data.
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Mouse.php

Though there is still the problem that you can't clip the mouse to the window using SFML. But I guess your not interested in that.

I'll stay tuned to your next game ;)
Title: SFML2 - desktop mouse vs. renderwindow mouse [SOLVED]
Post by: Brendon on September 25, 2011, 09:20:04 pm
Thanks all, that solved the problem. I was grabbing the mouse relative to the desktop and not relative to the renderwindow.

My mouse code was:
Code: [Select]
this.mousePosX = SFML.Window.Mouse.GetPosition().X;
this.mousePosY = SFML.Window.Mouse.GetPosition().Y;


And the correct way to do it is:
Code: [Select]
this.mousePosX = SFML.Window.Mouse.GetPosition(myRenderWindow).X;
this.mousePosY = SFML.Window.Mouse.GetPosition(myRenderWindow).Y;