Clearing Callbacks

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
Codiak
Prole
Posts: 12
Joined: Mon Aug 30, 2010 4:05 pm

Clearing Callbacks

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Clearing Callbacks

Post 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.
Help us help you: attach a .love.
Codiak
Prole
Posts: 12
Joined: Mon Aug 30, 2010 4:05 pm

Re: Clearing Callbacks

Post 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.
Codiak
Prole
Posts: 12
Joined: Mon Aug 30, 2010 4:05 pm

Re: Clearing Callbacks

Post 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().
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Clearing Callbacks

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests