Conditional tweening confusion
Posted: Sun Sep 02, 2018 7:48 pm
I apparently have a fundamental misunderstanding of how updating works during a tween. My goal is to have a draw function that activates a tween (color fade) when a key is pressed. I'm using the HUMP library, following this documentation of the tween function:
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.
I feel I am missing a very basic concept. Given the behavior that I observed, I first assumed that it was a misunderstanding of the Timer.update(dt). But related forum posts have me more confused (note: Timer.after is a similar function in the HUMP library, but the first argument being delay rather than duration). From viewtopic.php?t=82424 :
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!