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

Author Topic: sf::Mouse::getPosition lags behind the mouse curser  (Read 2171 times)

0 Members and 1 Guest are viewing this topic.

sw

  • Newbie
  • *
  • Posts: 8
    • View Profile
sf::Mouse::getPosition lags behind the mouse curser
« on: September 02, 2016, 05:45:10 pm »
Hello,

i'm using a sf::Sprite instead of the normal windows mouse curser. I have set the mouse curser invisible through

Code: [Select]
sf::Window::setMouseCursorVisible(false).
Then I set the mouse sprite at the mouse position:

Code: [Select]
setPosition(sf::Vector2f(window.mapPixelToCoords(sf::Mouse::getPosition(window))));
I call this function every frame.
The problem is now that the mouse "lags" behind the real mouse curser position. I can see this when I set the mouse curser visible (with sf::Window::setMouseCursorVisible(true)) and move the mouse around. The mouse sprite is always a bit behind the windows curser, it feels like a few frames.
Why is it so? Can I somehow fix this?

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Mouse::getPosition lags behind the mouse curser
« Reply #1 on: September 02, 2016, 07:01:46 pm »
The position of the sprite is the position of the mouse at the time you get that mouse position. It then takes a little time to process the frame/tick/cycle and then draw and display the window by which time the mouse may have moved slightly.
Although, it only lags when moving very quickly (at maximum, only one frame), the position that can then be used for calculations is the position of the mouse exactly.

It is possible to replace the actual mouse cursor but this requires more specific operating system code and is (currently*?) outside of SFML's scope.

p.s. Notice that you only really notice the apparent lag when you see the two together. It's reasonably responsive enough and the "lag" is pretty much invisible when you can't actually compare the two.

* there has been discussion about implementing this in SFML and there is certainly at least one pull request so it looks like it may possibly be included in a future version.
« Last Edit: September 02, 2016, 09:32:44 pm by Laurent »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: sf::Mouse::getPosition lags behind the mouse curser
« Reply #2 on: September 03, 2016, 10:50:09 am »
* there has been discussion about implementing this in SFML and there is certainly at least one pull request so it looks like it may possibly be included in a future version.

Past tense is somewhat inaccurate here. Currently: missing implementations for Windows and Linux (probably based on #1138), but anyone can contribute those.  ;)
SFML / OS X developer

sw

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Mouse::getPosition lags behind the mouse curser
« Reply #3 on: September 03, 2016, 09:26:09 pm »
Ok, thanks for your answers.

 

anything