So I have stumbled into a minor blockade again fallowing an old tutorial that I have managed to slowly convert into 2.1.
The problem here is that since window.GetInput() is no Longer Usable since that function is from SFML 1.6, I found that the new way to do things in 2.1 is different. I'll post the sample of code in case someone in the future is fallowing the CodingMade Easy Platformer tutorials.
SFML 1.6
InputManager.h
#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H
#include <vector>
#include <SFML/Window.hpp>
#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,int key);
bool KeyDown(sf::RenderWindow &Window, std::vector<int> keys);
private:
sf::Event event;
};
#endif
InputManager.cpp
#include "InputManager.h"
InputManager::InputManager()
{
}
InputManager::~InputManager()
{
}
void InputManager::Update(sf::Event event)
{
this->event = event;
}
bool InputManager::KeyPressed(int key)
{
if (event.Key.Code == key)
return true;
}
bool InputManager::KeyPressed(std::vector<int> keys)
{
for (int i = 0; i < keys.size(); i++)
{
if (event.Key.Code == keys[i])
return true;
}
return false;
}
bool InputManager::KeyReleased(int key)
{
if (event.Key.Code == key && sf::Event::KeyReleased)
return true;
return false;
}
bool InputManager::KeyReleased(std::vector<int> keys)
{
for (int i = 0; i < keys.size(); i++)
{
if (event.Key.Code == keys[i] && sf::Event::KeyReleased)
return true;
}
return false;
}
bool InputManager::KeyDown(sf::RenderWindow &Window, int key)
{
if (Window.GetInput().IsKeyDown(key))
return true;
return false;
}
bool InputManager::KeyDown(sf::RenderWindow &Window, std::vector<int> keys)
{
for (int i = 0; i < keys.size(); i++)
{
if (Window.GetInput().isKeyDown(keys[i]))
return true;
}
return false;
}
You can Notice the difference Since in 1.6 you have to put "event.Key.Code" in capitals while in 2.1 is lower case.
SFML 2.1
The Guy has alot of errors in his "C++ Sfml Platformer Made Easy Tutorial 6 - InputManager [Part 1]" tutorial but he probably covers them in part 2.
The really problem that I'm trying to solve is How would I implement "sf::Keyboard::isKeyPressed" in the header file would replacing things to this help:
bool KeyDown(sf::Keyboard::isKeyPressed,int key);
bool KeyDown(sf::Keyboard::isKeyPressed, std::vector<int> keys);
//or would removing int key, and the vector help ?
if everything works Ill post the sfml 2.1 converted version here.