Giter Club home page Giter Club logo

Comments (6)

usysrc avatar usysrc commented on July 17, 2024 1

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.

HTV04 avatar HTV04 commented on July 17, 2024

@usysrc This is a good workaround, but the precision issue still exists.

from hump.

usysrc avatar usysrc commented on July 17, 2024

there is no precision issue, the value is correct inside the after function

from hump.

HTV04 avatar HTV04 commented on July 17, 2024

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.

usysrc avatar usysrc commented on July 17, 2024

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.

HTV04 avatar HTV04 commented on July 17, 2024

I see. I guess this can't be worked around, so I'll close this issue.

from hump.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.