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

Author Topic: Questions about sf::Input  (Read 2340 times)

0 Members and 1 Guest are viewing this topic.

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Questions about sf::Input
« on: January 02, 2011, 03:09:51 am »
Hi, I am wondering how does sf::Input work, does it works as how the tutorial said? which is have a boolean variable to store the key state/mouse button state? And this boolean variable will be flag accordingly to the Event?

I roughly understand the need for sf::Input for realtime inputs. However I don't really understand why the need for sf::Input::GetMouseX/Y. Wouldn't the mouse position from the event suffice for realtime input?

Since I assume that whether a person get the mouse position from the Event or from the sf::Input, wouldn't it be the same until the next mouse move sf::event is fired?

regards

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
Questions about sf::Input
« Reply #1 on: January 02, 2011, 06:45:16 am »
The difference between the Input::GetMouseX/Y and the Event::MouseMove::X/Y is that Event::MouseMove is called only when the mouse is moved. And yes, Input acts as if a boolean is being set. Write a bit of code and try it yourself! :D

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Questions about sf::Input
« Reply #2 on: January 02, 2011, 07:25:06 am »
but won't the mouse position from sf::Event and sf::Input yield the same result?

e.g
1. Get mouse coord e.g (250, 280)
2. store the mouse coord in the my program
3. mouse is moved to (270, 200)
4. an sf::Event is fired off by the OS
5. Read sf::Event from event loop and update the new mouse coord

Suppose I do something as above, would it be less real time from the sf::Input version?

regards

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
Questions about sf::Input
« Reply #3 on: January 02, 2011, 09:28:22 am »
Yes. sf::Event will only fire when the mouse is moved, but sf::Input always fires (so is arguably a bit more responsive). As far as I have experienced, there is no difference in response.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Questions about sf::Input
« Reply #4 on: January 02, 2011, 12:22:38 pm »
sf::Input is just there so that you don't have to store the keyboard/mouse/joystick/... states yourself. sf::Input is really nothing more than a bunch of booleans and numbers that are updated when events are triggered.
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Questions about sf::Input
« Reply #5 on: January 02, 2011, 02:19:34 pm »
Like Laurent said.  Just think of it as being a helper class that remove work that you otherwise would do.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio