Page 1 of 1

Clearing Callbacks

Posted: Tue Sep 14, 2010 2:06 pm
by Codiak
I've reached the stage where I would like some state management system in my game so I can have screens for a title, game and game over screen. The way I'm doing this is by loading it's .lua file like this:
love.filesystem.load('screen.lua')()

The problem is functions like love.draw() are still running from the previous screen so the game freezes for a time on transition. I have tried clearing these by doing this:
function empty() end
love.draw = empty

and replacing 'function love.draw()' with:
love.draw = function()

But nothing works.

Re: Clearing Callbacks

Posted: Tue Sep 14, 2010 5:38 pm
by Robin
You want the screen to be black in between or something?

The reason it stays the same for some amount of time is probably because of the loading taking some time. Transitioning to another state is probably better done by, y'know, setting a state, rather than loading a file.

Re: Clearing Callbacks

Posted: Wed Sep 15, 2010 2:16 pm
by Codiak
The thing is when I remove what's in love.draw() in the title screen file and load back and forth between it and the game file it does so smoothly. It seems it doesn't like it when there are more than one love.draw() functions in different files. I know I could have a state variable to say when to run certain code in the same function, but if there is a way to make my way work I would like to know as I think it's more efficient.

Re: Clearing Callbacks

Posted: Wed Sep 15, 2010 3:22 pm
by Codiak
Oh hang on, solved it. I was setting fonts like this in love.draw():

love.graphics.setFont(love.graphics.newFont(100))

So it must have been duplicating the font on every loop. Just needed to give the font a name out of the loop then put it in setFont().

Re: Clearing Callbacks

Posted: Wed Sep 15, 2010 3:26 pm
by bartbes
Oh god, that is horrible! Also, in case you do want to use a similar statement (responsibly) you can just pass the arguments to newFont to setFont, it'll automagically call newFont.