Gamestates

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
qrux
Prole
Posts: 28
Joined: Thu Nov 03, 2011 1:11 am

Gamestates

Post 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!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Gamestates

Post 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.
User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: Gamestates

Post 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)
User avatar
qrux
Prole
Posts: 28
Joined: Thu Nov 03, 2011 1:11 am

Re: Gamestates

Post by qrux »

Got it. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests