SFML community forums
Bindings - other languages => DotNet => Topic started by: ggggggggggggggg on March 13, 2016, 06:26:21 am
-
So I was looking over a friend's project, which was a platformer, and he was using input from the RenderWindow itself. And, if haven't already guessed, it didn't work well. I'm not sure what it's called, but when you use input from a window event it has that little pause between the initial invoke and then reoccurring invoke (not sure the exact the words to describe that...) But this can be averted by using an external variable.
So my question is this: would it be best to work around that problem using an external variable? Or is the RenderWindow events best used for things like control/UI? If using an external variable, wouldn't you basically have to write code twice? Once to set the current velocity (KeyPressed) and stop the input velocity (KeyReleased).
-
If you need the real state at real time of an input:
See this tutorial section (http://www.sfml-dev.org/tutorials/2.3/window-inputs.php)
And if you need to know the "holding time" , you can combine sf::clock (or <chrono> ) and sf::(InputDevice)::is(eventType)
-
Using events is perfectly fine. However if you want to do some action while the key is held, you shouldn't just check the KeyPressed event and wait for the key repeat to kick in. Instead you'd track the state with some boolean and for repeated actions use a clock. I'd suggest to take a look at Thor's action class.
sf::Keyboard/sf::Mouse are also an option.