Comments (6)
You could use the after
callback of the tween function.
https://hump.readthedocs.io/en/latest/timer.html#Timer.tween
Example:
local Timer = require "hump.timer"
local fade = {
0
}
love.update = function(dt)
Timer.update(dt)
end
love.draw = function()
love.graphics.setColor(255,255,255,fade[1])
love.graphics.rectangle("fill", 200, 200, 200, 200)
end
local fading = false
love.keypressed = function(key)
if not fading and key == "space" then
fading = true
if fade[1] == 0 then
Timer.tween(5, fade, {1}, "linear", function()
fading = false
end)
else
Timer.tween(5, fade, {0}, "linear", function()
fading = false
end)
end
end
end
from hump.
@usysrc This is a good workaround, but the precision issue still exists.
from hump.
there is no precision issue, the value is correct inside the after function
from hump.
There is, because of the way floating point values work. Otherwise, the example I showed in my initial post would always work, without the need for math.floor.
One way to solve this issue might be to set the subject to the target value after the timer is complete. While this would be a hacky way of fixing the issue, it would work.
Actually, now that I think about it, this could cause unexpected results in some cases (such as if the subject were changed at all during the timer), so never mind.
from hump.
These are floating point numbers. It is just the way it is. But if you need the target value you can get it inside the after function.
Timer.tween(5, fade, {1}, "linear", function() print(fade[1], fade[1] == 1) end)
from hump.
I see. I guess this can't be worked around, so I'll close this issue.
from hump.
Related Issues (20)
- Documentation typo HOT 1
- Documentation typo in "gamestate" HOT 1
- Timer: After caching timers "to_update", timer:cancel() doesn't apply until next timer:update() HOT 1
- Vector unexpected symbol HOT 1
- bug HOT 4
- [hump.gamestate] textinput callback doesn't work properly HOT 3
- Camera documentation missing explanation about some parameters - worldCoords
- LOVE 11.0 requires extra arguments to setCanvas() at times
- Some minor things outlined in a forum post HOT 1
- hump.signal - crashes when sending "clear", "remove" or any other signals that share a name with a Registry function name. HOT 1
- Is there any maintainer for this repo? HOT 9
- Do I have to manually clear used timers? HOT 1
- docs: camera:attach doesn't have any of its arguments listed in the docs
- Arguments to atan2 are reversed HOT 1
- [hump.timer] freeze timer HOT 1
- attempt to perform arithmatic on self.x and self.y doesnt work
- attempt to index local 'layer' (a nil value) HOT 1
- Would be nice if there's some method to check if the instance inherits from some class HOT 2
- [hump.signal] stopping signal propagation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hump.