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

Author Topic: Adding states to the game created in the SFML Book  (Read 1219 times)

0 Members and 1 Guest are viewing this topic.

Clockwork

  • Newbie
  • *
  • Posts: 47
    • View Profile
Adding states to the game created in the SFML Book
« on: April 06, 2014, 06:59:09 pm »
Hello everybody!

So I followed the SFML book and now I'm just editing it for a personal project, but I've encountered a project.  I'm trying to add a new state that can be accessed by a button the menu.  The code for the state compiles just fine, the button shows up and everything.  But whenever I try to click on the button I get this message (in the attached pics).  The code at Statestack,cpp, line 69 is this:
 
Could somebody please let me know whats going wrong?
Thanks!  ;D

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Adding states to the game created in the SFML Book
« Reply #1 on: April 06, 2014, 07:03:10 pm »
Corrected code tags:
The code at Statestack,cpp, line 69 is this:
State::Ptr StateStack::createState(States::ID stateID)
{
        auto found = mFactories.find(stateID);
        assert(found != mFactories.end()); /* This line in particular */

        return found->second();
}

You have to register the states in the stack, so it knows how to create a new instance for a specific enumerator. Here you see how it works.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Clockwork

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Adding states to the game created in the SFML Book
« Reply #2 on: April 06, 2014, 07:06:52 pm »
* sigh *

I figured it would be something that simple.  Well, thanks Nexus, it works perfectly now!

 

anything