Why do we need to put graphics in love.draw()?
Why do we need to put graphics in love.draw()?
Title pretty much says it all. Why can't we put graphics everywhere?
- 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()?
Because this is what happens when you run a game (the 'game loop' repeats for every frame):
http://en.wikipedia.org/wiki/Game_progr ... _structure
http://en.wikipedia.org/wiki/Game_progr ... _structure
- 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()?
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.
Re: Why do we need to put graphics in love.draw()?
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.
- 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()?
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.
Long of the short, just go with it.
Who is online
Users browsing this forum: No registered users and 7 guests