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

Author Topic: sf::Event -> mouse wheel?!  (Read 4880 times)

0 Members and 3 Guests are viewing this topic.

5gum

  • Newbie
  • *
  • Posts: 27
    • View Profile
sf::Event -> mouse wheel?!
« 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 ;)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Event -> mouse wheel?!
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

5gum

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: sf::Event -> mouse wheel?!
« Reply #2 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Event -> mouse wheel?!
« Reply #3 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)...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

5gum

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: sf::Event -> mouse wheel?!
« Reply #4 on: January 16, 2014, 11:04:06 pm »
Thanks, I'll try this tomorrow :)

5gum

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: sf::Event -> mouse wheel?!
« Reply #5 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.