1
General / How should inputs be handled properly on a game?
« on: June 22, 2013, 07:41:38 pm »
Hello,
I'm making my first game and I until now I have been handling inputs (keyboard and mouse) in each class separately. So in my Sprite Editor class I have a method called "handler" which check the inputs and make actions depending on what are them:
(the mouse position is sent to handler as I don't want to send the sf::RenderWindow to that method.)
But when I use the mouse in another class I also treat it in the same way as above. Of course I take care so that both classes wouldn't be in conflict using the same input at the same time.
The way I'm using is working, but something inside me tells that it is the worst way of doing it. How should I properly handle inputs with SFML?
Thank you.
I'm making my first game and I until now I have been handling inputs (keyboard and mouse) in each class separately. So in my Sprite Editor class I have a method called "handler" which check the inputs and make actions depending on what are them:
void SpriteEditor::handler(sf::Vector2i mousePosition)
{
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
//Code here
}
}
{
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
//Code here
}
}
(the mouse position is sent to handler as I don't want to send the sf::RenderWindow to that method.)
But when I use the mouse in another class I also treat it in the same way as above. Of course I take care so that both classes wouldn't be in conflict using the same input at the same time.
The way I'm using is working, but something inside me tells that it is the worst way of doing it. How should I properly handle inputs with SFML?
Thank you.