Hello. I'm kinda new in Love2d. I was only working with Flash before.
I have a question: what's the point of having two functions called after each other instead of one?
There is already a topic about it: viewtopic.php?f=4&p=64353
But I want to understand, what's the problem of using it.
local asteroids = {}
function love.update(dt)
for _,a in ipairs(asteroids) do
a.x = a.x + a.sx * dt
a.y = a.y + a.sy * dt
end
end
function love.draw()
for _,a in ipairs(asteroids) do
love.graphics.draw(a.image, a.x, a.y, a.rotation)
end
end
Instead of having one cycle I have two. Won't it make my game slower?
You don't have to worry about speed until you really are having problems.
The idea behind love.update and love.draw is that you separate the game update logic from the game drawing. If the two are connected too tightly, it might get harder to modify things without breaking the drawing later on.
This is of course just a design choice thing. You can do it however you want.
Boolsheet wrote:This is of course just a design choice thing. You can do it however you want.
To clarify, you can change love.run (the actual run loop) to do whatever you want, but the default love.run will clear the screen right before calling love.draw, so you can't actually draw to the main screen in love.update with the default love.run function.
It more or less forces you to seperate your game logic from your drawing, which is important because you only usually draw a very small part of your game world and you don't want to waste time drawing things that aren't on the screen. It's basically a seperation of concerns thing.