I have created an inputmanager class which handles all the input in my game. What I have done is set EnableKeyRepeat to false so that it helps for single key presses. Anyways it works fine until you try to check for input using the arrow keys.
Whenever I do input using the arrow keys it treats it as continuous input but when I use other key codes it treats it as a single key press :/. Here's my inputmanager code
InputManager.h
#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H
#include<vector>
#include<SFML/Graphics.hpp>
class InputManager
{
public:
InputManager();
~InputManager();
void Update(sf::Event event);
bool KeyPressed(int key);
bool KeyPressed(std::vector<int> keys);
bool KeyReleased(int key);
bool KeyReleased(std::vector<int> keys);
bool KeyDown(sf::RenderWindow &Window, sf::Key::Code key);
bool KeyDown(sf::RenderWindow &Window, std::vector<sf::Key::Code> keys);
protected:
private:
sf::Event event;
};
#endif // INPUTMANAGER_H
InputManager.cpp
#include "InputManager.h"
InputManager::InputManager()
{
//ctor
}
InputManager::~InputManager()
{
//dtor
}
void InputManager::Update(sf::Event event)
{
this->event = event;
}
bool InputManager::KeyPressed(int key)
{
if(event.Key.Code == key && event.Type == sf::Event::KeyPressed)
return true;
return false;
}
bool InputManager::KeyPressed(std::vector<int> keys)
{
for(int i = 0; i < keys.size(); i++)
{
if(KeyPressed(keys[i]))
return true;
}
return false;
}
bool InputManager::KeyReleased(int key)
{
if(event.Key.Code == key && event.Type == sf::Event::KeyReleased)
return true;
return false;
}
bool InputManager::KeyReleased(std::vector<int> keys)
{
for(int i = 0; i < keys.size(); i++)
{
if(KeyReleased(keys[i]))
return true;
}
return false;
}
bool InputManager::KeyDown(sf::RenderWindow &Window, sf::Key::Code key)
{
if(Window.GetInput().IsKeyDown(key))
return true;
return false;
}
bool InputManager::KeyDown(sf::RenderWindow &Window, std::vector<sf::Key::Code> keys)
{
for(int i = 0; i < keys.size(); i++)
{
if(Window.GetInput().IsKeyDown(keys[i]))
return true;
}
return false;
}
Thanks in advance