Loading the menu state from an XML file
We now have most of our state loading code in place and can make use of this in the MenuState
class. First we must do a little legwork and set up a new way of assigning the callbacks to our MenuButton
objects, since this is not something we could pass in from an XML file. The approach we will take is to give any object that wants to make use of a callback an attribute named callbackID
in the XML file. Other objects do not need this value and LoaderParams
will use the default value of 0
. The MenuButton
class will make use of this value and pull it from its LoaderParams
, like so:
void MenuButton::load(const LoaderParams *pParams) { SDLGameObject::load(pParams); m_callbackID = pParams->getCallbackID(); m_currentFrame = MOUSE_OUT; }
The MenuButton
class will also need two other functions, one to set the callback function and another to return its callback ID:
void setCallback(void(*callback)()) { m_callback = callback;} int getCallbackID() { return...