Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: A Quick Question about SFML Game Development book and source code  (Read 3008 times)

0 Members and 1 Guest are viewing this topic.

twiggystardust

  • Newbie
  • *
  • Posts: 8
    • View Profile
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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: A Quick Question about SFML Game Development book and source code
« Reply #1 on: October 06, 2013, 09:13:19 pm »
The SFML Game Development is explaining the theory behind various concepts, thus shows some implementation details, but to keep the book focused on topic, leaves out other code snippets. If you're in for the full source code, then you can take a look at the repo on Laurent's GitHub page.

In short, the book tries to teach the theory and doesn't hold your hand throughout the book, by explaining every last piece and bit of one implementation. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

twiggystardust

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: A Quick Question about SFML Game Development book and source code
« Reply #2 on: October 07, 2013, 05:32:56 am »
OK, I understand. I had a slight thought that this might be the case. So no worries. I was under the understanding that it was. I did get the code e-mailed to me and have downloaded the updated code on github. Thanks!

twiggystardust

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: A Quick Question about SFML Game Development book and source code
« Reply #3 on: October 08, 2013, 05:54:13 am »
OK so I have another question. This time it's help with the code I'm getting some strange output messages and my code will not compile. this is the output message:
1>  PauseState.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sstream(10): error C2143: syntax error : missing ';' before 'namespace'
1>  Application.cpp
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2143: syntax error : missing ';' before 'Application::TimePerFrame'
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2734: 'sf::Time' : const object must be initialized if not extern
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2512: 'PauseState' : no appropriate default constructor available
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2373: 'TimePerFrame' : redefinition; different type modifiers
1>          c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.h(26) : see declaration of 'TimePerFrame'
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2440: 'initializing' : cannot convert from 'sf::Time' to 'int'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(31): error C2146: syntax error : missing ';' before identifier 'timeSinceLastUpdate'
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(31): error C2065: 'timeSinceLastUpdate' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(35): error C2146: syntax error : missing ';' before identifier 'dt'
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(35): error C2065: 'dt' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(36): error C2065: 'timeSinceLastUpdate' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(36): error C2065: 'dt' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(37): error C2065: 'timeSinceLastUpdate' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(37): fatal error C1903: unable to recover from previous error(s); stopping compilation

now, I've checked my code a few time, and honestly as far as I can tell it's identical. Also, one reason I find this output message odd is because of the first error message. Why would a standard library file have an error? Also I looked in the file, there is no namespace in the file at all. I'm at a loss here, any help please?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: A Quick Question about SFML Game Development book and source code
« Reply #4 on: October 08, 2013, 06:24:43 am »
Googling error messages often helps.

The first few results say the the top error (which is the most bizarre) is likely complaining about a real missing semicolon in some other location, probably at the end of a struct/class you defined.

twiggystardust

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: A Quick Question about SFML Game Development book and source code
« Reply #5 on: October 09, 2013, 01:09:20 am »
Yep, at the end of one of my include files, thanks