Page 1 of 1

Gamestates

Posted: Mon Dec 19, 2011 10:20 pm
by qrux
Can someone explain the basics of gamestates for me please? I have read some people suggesting stuff like hump and other libraries, but i want to try and build it myself first.
I don't quite understand it, like how you "wrap" the, let's say game code, and separate it from the menu code?
Do you just take all the game code and throw it into a function, then run that function when the user presses "Start" on the menu? (which itself is a menu function?)

Thanks!

Re: Gamestates

Posted: Mon Dec 19, 2011 11:05 pm
by bartbes
It's not a single function.
Let's explain it like this:
A state is a collection of callbacks (so they all have an update, a draw, etc), and a state manager is then designed in a way that you can easily select an active state.
The active state is the one that receives the callbacks, so if you switch to the "menu" state, that will then react to update, draw, keypressed, mousepressed, etc.

Re: Gamestates

Posted: Tue Dec 20, 2011 4:10 am
by osgeld
i just make a variable and use if's

gamestate = "menu"

if gamestate == "menu" do menu stuff
elseif gamestate == "playing" do playing stuff

but its a bit more of a pain in the butt due to love's callbacks, you have to have that in each appropriate section (like draw and update)

Re: Gamestates

Posted: Tue Dec 20, 2011 10:08 pm
by qrux
Got it. Thanks!