SFML community forums

Help => General => Topic started by: 5gum on January 16, 2014, 10:45:15 pm

Title: sf::Event -> mouse wheel?!
Post by: 5gum on January 16, 2014, 10:45:15 pm
Hey guys, it's me again ;D

In the SFML, there is stuff I unterstand really good.
In the SFML, there is stuff I understand a little bit.
But in the SFML, there is also stuff I really don't unterstand. And this stuff is called sf::Event...

I've got a map and sf::view. If I scroll up the mouse wheel the map should zoom in and vice versa (Sry, my English could be bad ::)). I tried it with:

while(window.pollEvent(event))
{
  if(event.mouseWheel.delta == 1)
  {
    view.zoom(0.9f);
  }
}

Yeah, it works!
But what unfortunately also works is if I click right mouse button and if I release right mouse button the view also zooms in.

I tried it with:

 if(event.mouseWheel.delta == 1 && !sf::Mouse::isButtonPressed(sf::Mouse::Button::Right))
  {
    view.zoom(0.9f);
  }


Now it "just" zoom in if I release the right mouse button.
But I don't want that the view zooms after right relase, only after wheel...
What I have to do?

Thanks a lot,

5gum

PS: I try your ideas only tomorrow afternoon cause I'm tired of programming today ;)
Title: Re: sf::Event -> mouse wheel?!
Post by: Nexus on January 16, 2014, 10:48:07 pm
Please read the tutorial carefully. You're doing basic things wrong, such as not checking for the event type before accessing its members, or mixing real-time input with event handling.
Title: Re: sf::Event -> mouse wheel?!
Post by: 5gum on January 16, 2014, 10:51:12 pm
My English is really bad so I don't understand the details of the documentation. Could you give me a hint what I do wrong?
Title: Re: sf::Event -> mouse wheel?!
Post by: Nexus on January 16, 2014, 10:58:30 pm
You're doing basic things wrong, such as not checking for the event type before accessing its members, or mixing real-time input with event handling.
What I meant is that you need to check the variable event.type before you use a specific event like the mouse wheel in event.mouseWheel.delta. You have to make sure you actually deal with a mouse wheel event.

I can't describe it better than in the tutorial. If you don't understand it, you should use a translator tool or improve your English (as a game developer, you won't get around it anyway)...
Title: Re: sf::Event -> mouse wheel?!
Post by: 5gum on January 16, 2014, 11:04:06 pm
Thanks, I'll try this tomorrow :)
Title: Re: sf::Event -> mouse wheel?!
Post by: 5gum on January 17, 2014, 01:12:08 pm
OK it works, thanks :)

I also have read the tutorial about events and think I understand it now.