Hello,
I'm trying to write a callback event system in DirectX9. I'm attempting to use method function pointers to trigger events to mouseclicks; but I'm having some problems. My game uses a gamestate manager to manage the rendering. All of my gamestates are derived from a base class AbstractGameState.
I have a sprite object with this specific method:
m_NewGameSprite->OnClick(this, &MainMenuState::StartGame);
MainMenuState is the current gamestate that my game is in, and StartGame is a void method part of this class. I'd like to store the function pointer in a variable within my sprite class so that I can execute it when the user clicks.
template <typename T>
void OnClick(GameState* LinkedState, void (T::*EventPointer)())
{
m_LinkedGameState = LinkedState;
m_EventPointer = EventPointer; // <- Doesnt compile
}
I've tried downcasting the pointer, but that didn't really work.
My sprite class also contains these two variables
void (GameState::*m_EventPointer)();
GameState* m_LinkedGameState;
Any help would be appreciated