Sign in to follow this  

Input System

Recommended Posts

I'm currently working on project using sdl which uses a gamestate system.  


Here's some psuedo code of how it works right now:

    //SDL event loop ...

    case SDLK_m:
        changeState(STATE_MENU); //Changes the state which updates in manageState()


    //Makes sure we can delete the state, if so - delete it
    delete currentState;

        case STATE_MENU:
            currentState = new Menu();




What I am looking to do is for each state, which is represented by a class that inherits from the abstract base class of GameState, is for it to have its own event loop.  I was going to do it this way because the menu could have a totally different use for a key than the game itself.


The problem I'm running into is that I can't make a call to change the state from within that event loop.  I need to be able to change the state and destroy the object in GameEngine and create it again so the GameEngine render and update functions can call the currentState->Render and update functions.


There may be a simple solution for this but its been driving me nuts lately.  It is kind of difficult to explain so if you need further clarification I would be happy to do so.  Thanks for the help smile.png

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this