examples,
A:
Code: Select all
function love.draw()
end
function love.update(dt)
end
Code: Select all
function love.update(dt)
end
function love.draw()
end
Code: Select all
function love.draw()
end
function love.update(dt)
end
Code: Select all
function love.update(dt)
end
function love.draw()
end
Thank you ,your explanation is very helpful!Jasoco wrote:If you look at the love.run function link posted above you'll see exactly when each part is executed. You can make your own love.run if you need to. I did a few times. In my case I had moved the love.clear call to before love.update so I could still use drawing commands in love.update for debugging purposes since I could then draw useful information inside a loop and not have to run that loop again in love.draw later. (Since by default anything you draw in update gets erased before it even gets shown.)
I had also made dt a global variable so I could access it from anywhere (Since it's very useful) instead of having to pass it through every function. Someone had once said it was a pretty good idea. But it'll remain local by default. But you can make it global if you have to.
love.run does change occasionally though. When we went from 0.7 to 0.8 it changed the way sleep worked and I had thought my games were broken.
Code: Select all
function love.run()
...
dt=0 --remove the "local" keyword?
...
end
One could. But I prefer to just make it global anyway. But only if I'm bothering to use a custom love.run(). Unless there's a drawback to having dt be global at all times vs. just calling getDelta() when you need it.bartbes wrote:Alternatively, one could just call love.timer.getDelta().
dwdcth wrote: Thank you ,your explanation is very helpful!
You said that you had made dt a global variabl.Do you do like this?Code: Select all
function love.run() ... dt=0 --remove the "local" keyword? ... end
bartbes wrote:Alternatively, one could just call love.timer.getDelta().
Actually, When I need to access dt out of love.update, i am using a local dt var upvalue, defined in main.lua. I find it simpler (but I might be wrong). It works fine, though. I share it, for what it's worth.Jasoco wrote:One could. But I prefer to just make it global anyway. But only if I'm bothering to use a custom love.run(). Unless there's a drawback to having dt be global at all times vs. just calling getDelta() when you need it.
Code: Select all
-- main.lua
local dt
function love.load()
-- some code
end
function love.update(delta_time)
dt = delta_time
-- some code, using now dt, as usual
end
function love.draw()
-- can access dt here, as upvalue
end
-- etc, same logic with others callbacks
Well, a little precision, though. In my example, dt is not global. It is just a local variable, accessible from everywhere in main.lua. As it is defined first, all functions caming after will consider dt as an upvalue.dwdcth wrote:Yeah,it's a simple waw to make dt a global value.
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests