Ok maybe i'm stupid

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
FRII
Prole
Posts: 22
Joined: Tue Feb 23, 2016 9:45 pm

Ok maybe i'm stupid

Post by FRII »

but why have love.update and love.draw be separate functions? they're both called every frame, correct? update before draw, right? so why have them be separate?
four years later and i hate remembering the posts i made on here exist but i can't delete any of them or my account
sorry you had to read this
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Ok maybe i'm stupid

Post by s-ol »

FRII wrote:but why have love.update and love.draw be separate functions? they're both called every frame, correct? update before draw, right? so why have them be separate?
first because they are supposed to do very different things and therefore should logically be seperate. And secondly, with a custom love.run they might not both run every frame at all.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Ok maybe i'm stupid

Post by Tesselode »

There's nothing inherently different about them. They're just split into update and draw for the sake of good organization. Also, update has the dt argument and draw doesn't, which reinforces that good organization.
FRII
Prole
Posts: 22
Joined: Tue Feb 23, 2016 9:45 pm

Re: Ok maybe i'm stupid

Post by FRII »

so what y'all're sayin' is that the title is more a definite than a an inquisitive statement
four years later and i hate remembering the posts i made on here exist but i can't delete any of them or my account
sorry you had to read this
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Ok maybe i'm stupid

Post by zorg »

More like the knowledge you lacked is now gained.
Now get back to work : 3
Me and my stuff :3True 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.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Ok maybe i'm stupid

Post by bobbyjones »

FRII wrote:but why have love.update and love.draw be separate functions? they're both called every frame, correct? update before draw, right? so why have them be separate?
They don't have to be separate. You could do all your updating in love.draw (actually some people do for technical reasons.) The only reason they are separate afaik is because of preference.
User avatar
unrecoverable
Prole
Posts: 4
Joined: Thu Nov 12, 2015 4:19 pm

Re: Ok maybe i'm stupid

Post by unrecoverable »

They're separated so that it's easier to prevent game logic from interfering with what's displayed on screen. Without that distinction you just have to be more careful all your game logic is running before your display code.
Sarcose
Prole
Posts: 48
Joined: Wed Jul 08, 2015 12:09 am

Re: Ok maybe i'm stupid

Post by Sarcose »

Isn't love.draw() the only function that will put anything on the screen when love.graphics functions such as rectangle() are called?

Further emphasizing the organization aspect.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Ok maybe i'm stupid

Post by zorg »

That's only because of what's inside the default love.run anyway.
Me and my stuff :3True 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.
User avatar
nkorth
Prole
Posts: 15
Joined: Sun Sep 18, 2011 8:54 pm
Contact:

Re: Ok maybe i'm stupid

Post by nkorth »

One reason to split update from draw: when you drag a window around, some operating systems will force it to redraw more frequently than it otherwise would. If the game can't redraw on demand, the window will flicker or turn black while it moves. I don't think Love2D does this by default, but you could make the draw function run when the OS requests a redraw, meaning it'd be running more often than the update function (and no flickering windows!)
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests