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

Author Topic: [2.0] Mouse Wheel  (Read 7931 times)

0 Members and 1 Guest are viewing this topic.

xzxvvxzx

  • Newbie
  • *
  • Posts: 7
    • View Profile
[2.0] Mouse Wheel
« on: June 21, 2013, 02:52:38 am »
Hello, I want to use mouse wheel but when I type:

int mouse_wheel;
if (event.type == sf::Event::MouseWheelMoved)
{
    mouse_wheel = event.mouseWheel.delta;
}
 

mouse_wheel is always 0. How to handle mouse scrolling? I am using Windows 7 and Microsoft Wireless Mobile Mouse 3500.

EDIT: It sometimes change to 1 but I need to move mouse wheel very fast. Is there any way to detect slow mouse wheel movement?
« Last Edit: June 21, 2013, 03:45:47 am by xzxvvxzx »

cooldog99

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • Perilous Game Studios
Re: [2.0] Mouse Wheel
« Reply #1 on: June 21, 2013, 05:58:12 am »
The mouse wheel event changes from -1 -> 1

it doesn't keep a total delta, only the amount of change in that event.

Common practice is to keep a global(doesn't have to be global, just outside the while loop) variable of mouse delta.

see below:

pseudo code:

Code: [Select]
int main(){
     int mouseDelta = 0;

     while loop{
            sf::event newEvent;
            while(window.pollEvent(newEvent)){
                   if (newEvent.type == sf::Event::MouseWheelMoved)
                   {
                         mouseDelta += newEvent.mouseWheel.delta;
                   }
            }
     }

      return 0;
}


Here is the official SFML 2 tutorial topic that may help.
http://www.sfml-dev.org/tutorials/2.0/window-inputs.php

also, next time, try to post complete minimal code, so we can diagnose errors better. :)
Hope this helps.

 

anything