Page 1 of 1
love.update() and love.draw()
Posted: Thu Jan 22, 2015 9:36 pm
by Dr.Tyler O.
This is a question that has been nagging at my curiosity for ages. I want to know if there are any cons in using love.draw for things that require updating instead of love.update.
For example:
Let's say I have a variable that needs to be updated to a random number every frame. Are there any cons in putting that variable update inside love.draw instead of love.update besides the idea of keeping your code organized?
Re: love.update() and love.draw()
Posted: Thu Jan 22, 2015 9:55 pm
by markgo
Your game should work normally without drawing anything. If you put your random code or game logic inside of love.draw, then you are not longer separating concerns.
Re: love.update() and love.draw()
Posted: Thu Jan 22, 2015 11:08 pm
by Positive07
love.update has dt passed to it which is an advantage, otherwise you would need to use love.timer.getDelta which implies calling a function and doing some other stuff, this is not really a problem is not like your game will freeze because you call this function.
The other benefit as you pointed out is being organized with your code
For anything else.... they are the same... if you have more doubts on it I recommend you take a look at [wiki]love.run[/wiki]
Re: love.update() and love.draw()
Posted: Fri Jan 23, 2015 6:48 am
by micha
In case you didn't know: You can have a look at LÖVE's game loop in
love.run.
Sticking to the update/draw separation is good practice and LÖVE's game loop has built it in by default so that beginners learn that right away. If you have a good reason to not separate updating and drawing, go ahead and do it! You may even change the overall game loop. Besides that, there is no 'hidden' disadvantage of mixing up updating and drawing.
Re: love.update() and love.draw()
Posted: Fri Jan 23, 2015 11:12 am
by s-ol
Dr.Tyler O. wrote:This is a question that has been nagging at my curiosity for ages. I want to know if there are any cons in using love.draw for things that require updating instead of love.update.
For example:
Let's say I have a variable that needs to be updated to a random number every frame. Are there any cons in putting that variable update inside love.draw instead of love.update besides the idea of keeping your code organized?
No delta time.
Re: love.update() and love.draw()
Posted: Fri Jan 23, 2015 11:18 am
by nfey
Well, this is really interesting. I didn't stumble upon that wiki page until now.
I have one question tho: what's the purpose of the sleep() call at the end of the while loop?
Code: Select all
if love.timer then love.timer.sleep(0.001) end
Doesn't this pretty much hardcode a thousandth of a second's worth of lag in each frame?
Re: love.update() and love.draw()
Posted: Fri Jan 23, 2015 11:45 am
by zorg
nfey wrote:...Doesn't this pretty much hardcode a thousandth of a second's worth of lag in each frame?
yes, but more importantly, it will prevent your love game from eating a whole cpu core just by doing nothing;
though you can indeed optimize that, and if i recall correctly, the vsync being turned off or on has some effects as well; there have been at least one other thread about this.
Re: love.update() and love.draw()
Posted: Fri Jan 23, 2015 4:28 pm
by Muris
Without the sleep, the love-game would use 100% cpu.
Re: love.update() and love.draw()
Posted: Sat Jan 24, 2015 12:32 pm
by nfey
Interesting. I'll try to dig up the other thread Zorg is telling us about.
Re: love.update() and love.draw()
Posted: Sat Jan 24, 2015 1:48 pm
by zorg