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.
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?
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
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.
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]
for i, person inipairs(everybody) do [tab]ifnot person.obey then person:setObey(true) end end
love.system.openURL(github.com/pablomayobre)
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.
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.
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?
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?
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.
Last edited by zorg on Fri Jan 23, 2015 7:40 pm, edited 1 time in total.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.