1
General / SFML Game Developmet - Problem With Commands
« on: April 08, 2015, 11:40:21 pm »
So I have been following the book SFML Game Development and I am right at the end of chapter 4 (Where we bind keys to actions). The code I have is:
and for some reason I can move up down and right but not to the left. I have looked all over my code and compared it to the source code: https://github.com/SFML/SFML-Game-Development-Book/tree/master/04_Input
Any ideas why I can't move left?
Player::Player()
{
mKeyBinding[sf::Keyboard::W] = MoveUp;
mKeyBinding[sf::Keyboard::A] = MoveLeft;
mKeyBinding[sf::Keyboard::S] = MoveDown;
mKeyBinding[sf::Keyboard::D] = MoveRight;
mActionBinding[MoveUp].action =
[] (SceneNode& node, sf::Time dt)
{
node.move(0.f, -0.1f * dt.asSeconds());
};
mActionBinding[MoveLeft].action =
[] (SceneNode& node, sf::Time dt)
{
node.move(-0.1f * dt.asSeconds(), 0.f);
};
mActionBinding[MoveDown].action =
[] (SceneNode& node, sf::Time dt)
{
node.move(0.f, 0.1f * dt.asSeconds());
};
mActionBinding[MoveRight].action =
[] (SceneNode& node, sf::Time dt)
{
node.move(0.1f * dt.asSeconds(), 0.f);
};
for(auto &pair : mActionBinding)
pair.second.category = Category::PlayerAircraft;
}
{
mKeyBinding[sf::Keyboard::W] = MoveUp;
mKeyBinding[sf::Keyboard::A] = MoveLeft;
mKeyBinding[sf::Keyboard::S] = MoveDown;
mKeyBinding[sf::Keyboard::D] = MoveRight;
mActionBinding[MoveUp].action =
[] (SceneNode& node, sf::Time dt)
{
node.move(0.f, -0.1f * dt.asSeconds());
};
mActionBinding[MoveLeft].action =
[] (SceneNode& node, sf::Time dt)
{
node.move(-0.1f * dt.asSeconds(), 0.f);
};
mActionBinding[MoveDown].action =
[] (SceneNode& node, sf::Time dt)
{
node.move(0.f, 0.1f * dt.asSeconds());
};
mActionBinding[MoveRight].action =
[] (SceneNode& node, sf::Time dt)
{
node.move(0.1f * dt.asSeconds(), 0.f);
};
for(auto &pair : mActionBinding)
pair.second.category = Category::PlayerAircraft;
}
and for some reason I can move up down and right but not to the left. I have looked all over my code and compared it to the source code: https://github.com/SFML/SFML-Game-Development-Book/tree/master/04_Input
Any ideas why I can't move left?