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.
Clearing Callbacks
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Clearing Callbacks
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.
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.
Re: Clearing Callbacks
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
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().
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().
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Clearing Callbacks
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.
Who is online
Users browsing this forum: Google [Bot] and 3 guests