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

Author Topic: Enhance sf::Input class  (Read 3750 times)

0 Members and 1 Guest are viewing this topic.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Enhance sf::Input class
« on: October 29, 2009, 06:48:07 pm »
I think that sf::Input is quite inneficient comparing to sf::Event.

It would be nice for sf::Input to have higher level functions, like:
bool isKeyHold(...);
bool isKeyPressed(...);
bool isKeyReleased(...);
and maybe
bool isMouseMoving();

is very simple to implement, and I think that everyone needs to know when a key is just pressed or released! I have to make a custom sf::RenderWindow class to implement this...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Enhance sf::Input class
« Reply #1 on: October 29, 2009, 07:46:05 pm »
Sorry i don't get it. What is the difference between isKeyPressed and isKeyHold? Between isKeyPressed and !isKeyReleased? What exactly does isMouseMoving mean?

sf::Input cannot be more efficient or less efficient than sf::Event: they both use the same base internally, except that sf::Event is directly forwarded to the user, whereas sf::Input stores states.
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Enhance sf::Input class
« Reply #2 on: October 29, 2009, 07:59:08 pm »
Sorry for not explaining well.

IsKeyPressed returns true just the frame when it has been pressed. The next frame, IsKeyPressed will return false, but IsKeyHold still returns true.
IsKeyHold is IsKeyDown.

It's pretty useful. Lots of games needs to check if a key is just pressed.

For example, you have a shooter game. You have a handgun and you want it to shoot every time you press Space (like shooting with a handgun in Counter Strike).

Edit: Forgey IsMouseMoving, it's pretty useless xD

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Enhance sf::Input class
« Reply #3 on: October 29, 2009, 08:09:18 pm »
Quote
IsKeyPressed returns true just the frame when it has been pressed. The next frame, IsKeyPressed will return false, but IsKeyHold still returns true.
IsKeyHold is IsKeyDown.

Ok I see.
I think that the idea of "frame" is not well-defined in the low-level context of SFML. I don't know if every SFML application has the same definition of a frame :)

Moreover, notifying events is clearly a job for sf::Event, what would be the pupose of duplicating these informations in sf::Input as well? The current implementation clearly separates the "event" behaviour on one side, and the "state" behaviour on another side. I think it is quite clean like this :)
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Enhance sf::Input class
« Reply #4 on: October 29, 2009, 08:42:33 pm »
You made me notice I was wrong.

You can use sf::Event to check if the key was just pressed, and sf::Input to check if it's hold by the user.

My fault :D

 

anything