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 » Mon Dec 19, 2011 10:20 pm

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 » Mon Dec 19, 2011 11:05 pm

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 » Tue Dec 20, 2011 4:10 am

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 » Tue Dec 20, 2011 10:08 pm

Got it. Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests