Jump to content

  • Log In with Google      Sign In   
  • Create Account


Jun*

Member Since 24 Aug 2013
Offline Last Active Jan 08 2014 11:42 AM
-----

#5105877 [C++][ALLEGRO5] How to make a Title screen and different screen states?

Posted by Jun* on 31 October 2013 - 12:45 AM

 

How do I make , for example a Title screen and when an option is selected, for example "Play game", the screen switches to the gameplay screen?
Do I have to clear the screen and then enter the game loop?
Do I need to make Individual loops inside the main gameoop for different screens, if yes, can you provide a quick example?

I still don't understand the screen states.

Read up on state machines, they'll help out here. What you want to do in this case is to use a state machine and transition to and from states. Implementations can be simple or complex, but you should only use one game loop.

Here's a small example: 
set state to 'title screen'
while game is still running:
    handle input
    
    update according to state:
        when state is 'title screen':
            update timer
            update fade animation
            if timer expired or user pressed skip button:
                set state to menu
        
        when state is 'menu':
            navigate menu according to user input
            if user pressed 'start game' GUI button:
                set state to 'game'
            
        when state is 'game':
            if user pressed menu button:
                set state to 'menu'
            update game
    
    render according to state:
        when state is 'title screen':
            draw splash screen
            draw fade transition

        when state is 'menu':
            draw menu
            draw selected item
            
        when state is 'game':
            draw game
    
    present image

Amazing, thanks alot!
Although, essentially it's the same thing I thought of,just cleaner. The functions would be still loops till the user prompts(example, selects "Play game").
But thanks for clearing it up.




PARTNERS