Below is the latest code I've tried. However, after pressing the key ('a'), instead of setting the background to green and fading to black over 10 seconds, the background fades between green and black about 1/s over the 10 seconds. Also, when it completes, I am unable to activate the tween again. Alternatively, if I place the same Timer.tween call within the love.load() function and press ('a'), the fade occurs slowly, as intended, but begins at an intermediate time within the 10 seconds (ie, the later I push the key, the more faded the starting point). Again, this cannot be reactivated with another key press.
Code: Select all
Timer = require 'hump.timer'
function love.load()
color = {0, 255, 0}
end
function love.update(dt)
Timer.update(dt)
end
function love.keypressed(key)
if key == 'escape' then love.event.quit()
elseif key == 'a' then fade = true
end
end
function love.draw()
love.graphics.setBackgroundColor({0, 0, 0})
if fade == true then
Timer.tween(10, color, {0, 0, 0}, 'linear', function() fade = false end)
love.graphics.setBackgroundColor(color)
end
end
and...palmettos wrote: ↑Fri Jul 08, 2016 2:32 pm The number argument to Timer.after is the number of seconds Timer waits to call the function argument after Timer.after is called. At what time the entire love program starts is irrelevant.
Say you put Timer.after(3, function() print('hello') end) in the love.mousepressed callback. Anytime the user presses a mouse button, 'hello' will print to the console 3 seconds later.
Any clarity here is greatly appreciated. Thanks!