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?
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.
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.