Loading other states from an XML file

Our MainMenuState class now loads from an XML file. We need to make our other states do the same. We will only cover the code that has changed, so assume that everything else has remained the same when following through this section.

Loading the play state

We will start with PlayState.cpp and its onEnter function.

bool PlayState::onEnter()
  // parse the state
  StateParser stateParser;
  stateParser.parseState("test.xml", s_playID, &m_gameObjects, 

  std::cout << "entering PlayState\n";
  return true;

We must also add the new texture clearing code that we had in MainMenuState to the onExit function.

// clear the texture manager for(int i = 0; i < m_textureIDList.size(); i++) { TheTextureManager::Instance()-> ...

Get SDL Game Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.