Everytime somebody shows code from the CodingMadeEasy tutorial, it's just questionable (see
here and
here). I don't recommend to follow his tutorials, they teach very bad C++ style and wrong SFML usage.
Concrete example:
bool KeyReleased(int key);
bool KeyReleased(std::vector<int> keys);
Keys are not stored as
int, but
sf::Keyboard::Key. There's no need to lose type safety. Furthermore, it's unnecessary to copy the whole container, a const reference would do. Additionally, the container overload could call the simple overload to avoid code duplication.
bool InputManager::KeyReleased(int key)
{
if (event.Key.Code == key && sf::Event::KeyReleased)
return true;
return false;
}
Not only is the if condition unnecessary (a direct
return would also work), but here it's also plain wrong.
sf::Event::KeyReleased is a constant.
InputManager::~InputManager()
{
}
Again unnecessary. See also rule of three/five.
The whole design of
InputManager is flawed. It stores a single event and constantly overrides it. The idea of such abstractions is to separate input handling and game logic, which is exactly
not possible in the case here, because one needs to update and poll InputManager for every single event -- in the end, you have a lot of boilerplate code that simplifies
nothing.
I honestly don't think it's worth to fix his codes or port them to SFML 2.1, since they're fundamentally broken. You should rather have a look at the tutorials of people who know how to program in C++. For example,
those of SuperV1234 are very nice.