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

Author Topic: Mouse Movements  (Read 189 times)

0 Members and 1 Guest are viewing this topic.

alikroos

  • Newbie
  • *
  • Posts: 3
    • View Profile
Mouse Movements
« on: April 04, 2024, 08:10:44 pm »
How to reduce the Speed of a sprite while moving it with the Mouse, because if the mouse moves too fast the view would move to fast also ,so how could we reduce the speed.

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Mouse Movements
« Reply #1 on: April 05, 2024, 12:18:07 pm »
It's impossible to answer without knowing how you do it. There's many ways to "move a sprite with the mouse".

alikroos

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Mouse Movements
« Reply #2 on: April 05, 2024, 10:58:53 pm »
I did it with getting the position of the mouse, the Sprite is moving the function Mouse::getPosition(), but how could i make the Sprite Slows down when the mouse is moving really fast, should I use another method of moving the Sprite with the mouse?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10835
    • View Profile
    • development blog
    • Email
Re: Mouse Movements
« Reply #3 on: April 06, 2024, 05:05:23 pm »
To me it's rather unclear what problem you're seeing. The mouse can only move at a certain speed over your window. If it's a 1:1 mapping then it would just move as fast as you see your mouse move, I don't understand why you think this is too fast, nor what it has to do with the view.

Maybe post some code and explain what you want to achieve, so we can understand the problem.

Personally, I'd recommend using events to track mouse position, instead of using sf::Mouse::getPosition()
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

kojack

  • Sr. Member
  • ****
  • Posts: 318
  • C++/C# game dev teacher.
    • View Profile
Re: Mouse Movements
« Reply #4 on: April 06, 2024, 05:57:49 pm »
You could average (maybe weighted lerp) the mouse position and the sprite.

Or calculate the difference between the current and previous mouse positions as a vector, then if the magnitude of the vector is too long (so speed is too high) then rescale the vector. Use this vector (whether scaled or not) to move the sprite.