Why do we need to put graphics in love.draw()?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
LuaMaster
Prole
Posts: 13
Joined: Tue Jan 01, 2013 2:33 am

Why do we need to put graphics in love.draw()?

Post by LuaMaster »

Title pretty much says it all. Why can't we put graphics everywhere?
User avatar
slime
Solid Snayke
Posts: 3170
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Why do we need to put graphics in love.draw()?

Post by slime »

Because this is what happens when you run a game (the 'game loop' repeats for every frame):

Image

http://en.wikipedia.org/wiki/Game_progr ... _structure
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Why do we need to put graphics in love.draw()?

Post by BlackBulletIV »

Expanding on what slime said, the update logic needs to be separated from the rendering. This is why we have two separate callbacks, love.update and love.draw. love.run is the function that contains the game loop (it's automatically defined by LÖVE) and calls these functions; you may want to take a look at that.
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Why do we need to put graphics in love.draw()?

Post by Tesselode »

Also, keeping game code and rendering separated is good for the organization of a game. Don't let things that don't go together go together.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Why do we need to put graphics in love.draw()?

Post by Jasoco »

As was said, it's mainly for organization. Keeping things in place so it's not a big mess. If you really really need to you can supply your own version of the love.run function to move the love.graphics.clear() call before the love.update function so you can draw in update. Or go further and just have one mishmashed love.doeverythingintheentiregame function that holds all the update and draw code. But once again, this is going to be messy. Best keep update and draw separate unless it's extremely imperative that you have some updating and drawing being done at once.

Long of the short, just go with it.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests