So I've been working on this book for a little while and I just finished chapter four. My question is: Is there supposed to be different code in the example code than the book? As far as chapter four goes, in the book there's this code, it's the last bit of code in the chapter:
Chapter 4 book pg 111
Player::Player()
{
mKeyBinding[sf::Keyboard::Left] = MoveLeft;
mKeyBinding[sf::Keyboard::Right] = MoveRight;
mActionBinding[MoveLeft].action = [] (SceneNode& node, sf::Time dt)
{
node.move(-playerSpeed * dt.asSeconds(), 0.f);
};
mActionBinding[MoveRight].action = [] (SceneNode& node, sf::Time dt)
{
node.move(playerSpeed * dt.asSeconds(), 0.f);
};
FOREACH(auto& pair, mActionBinding) pair.second.category = Category::PlayerAircraft;
}
So then I take a look in the example code and Player::Player() looks like this
Chapter 4 example code Source/Player.cpp
Player::Player()
{
// Set initial key bindings
mKeyBinding[sf::Keyboard::Left] = MoveLeft;
mKeyBinding[sf::Keyboard::Right] = MoveRight;
mKeyBinding[sf::Keyboard::Up] = MoveUp;
mKeyBinding[sf::Keyboard::Down] = MoveDown;
// Set initial action bindings
initializeActions();
// Assign all categories to player's aircraft
FOREACH(auto& pair, mActionBinding)
pair.second.category = Category::PlayerAircraft;
}
I'd say that's a bit different. And the initializeActions() function, was not even mentioned in the text. Why is this? Am I just supposed to do what the book says, then go back over the code and add everything in the example code to the project? I'm sorry if this is a stupid question or if I missed something, but I really don't know why this would be.