The logic of LÖVE's gamestate.

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
Aloud
Prole
Posts: 4
Joined: Fri Aug 21, 2015 7:44 am

The logic of LÖVE's gamestate.

Post by Aloud »

I'm having a hard time comprehending how the gamestate in LÖVE works; though I know for the most part that it involves creating a table or some sort. So far, I haven't seen any tutorial regarding this (and if there are, they tend to use the outdated version instead). Checking the source code of some LÖVE games is unfortunately of no help either, as they provide no inline documentation to easily help me figure out this problem.

Basically, for now I just want to know how to make a titlescreen gamestate consisting of a simple white background with three buttons (such as new game, options and exit). The selected button will have an arrow next to it, and it's controlled using the keyboard.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: The logic of LÖVE's gamestate.

Post by airstruck »

Love has no concept of gamestate (as far as I'm aware). You can use a drop-in solution like hump.gamestate or roll your own. It's mostly just a matter of forwarding callbacks (love.update/love.draw) and events to a different table of handlers for each gamestate, and storing some context (the actual "state") somewhere. You may also want a way to define things that happen when gamestates are loaded/unloaded, or manage a stack of active states.

Here's a rough outline:

Code: Select all

local game = {}

function game:setState (state)
    self.state = state
end

function love.update (...)
    return game.state.update(...)
end

function love.draw (...)
    return game.state.draw(...)
end

local menuState = {
    draw = drawMenu,
    update = updateMenu
}

game:setState(menuState)
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: The logic of LÖVE's gamestate.

Post by T-Bone »

If you were expecting functionality like this, there are probably other game creation tools that will suit you better. Game engines typically have these kinds of basic building -blocks built-in, which can speed up development. Personally, the main reason I'm using Löve is that it allows me to implement these kinds of things exactly the way I like.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests