Switching 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
Ezzam
Prole
Posts: 1
Joined: Tue Aug 23, 2011 8:40 am

Switching gamestates

Post by Ezzam »

This is my first post here, so hello everyone. I've got a problem with gamestates. Here's the main.lua:

Code: Select all

require 'game'
require 'menu'

game.load()

function love.load()

end

function love.update(dt)
currstate.update(dt)
end

function love.draw()
currstate.draw()
end

currstate = menu
First, i load game.lua so there won't be any errors. My game is based on love.physics. Game.lua is the level of the game, and i want to have menu done exactly the same way as level, but when i load menu gamestate, objects defined in game.lua are still on their places. Is there any way to unload a state, then load a new one?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Switching gamestates

Post by Robin »

You write a function to unload a state and call it?
Help us help you: attach a .love.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Switching gamestates

Post by T-Bone »

It kind of depends on your game. The way I do it in my own is that every state has a :start()-method, which resets the state and starts it up. There isn't really a need to unload an old state unless it takes up large amounts of memory, just reset the state when you switch to it.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Switching gamestates

Post by vrld »

With hump.gamestate there is a leave function that will be called when you switch the gamestate. This can be used to clean up the physics world or remove stuff from the scene manager (if you have one).
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests