SFML community forums
Help => Window => Topic started by: mercurio7891 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
-
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
-
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
-
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.
-
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.
-
Like Laurent said. Just think of it as being a helper class that remove work that you otherwise would do.