kikito / tween.lua Goto Github PK
View Code? Open in Web Editor NEWTweening/Easing/Interpolating functions for lua. Inspired on jQuery's animate method.
License: Other
Tweening/Easing/Interpolating functions for lua. Inspired on jQuery's animate method.
License: Other
I get the following error when I attempt to run the demo project. I'm on macOS High Sierra 10.13.6 using Love 11.2
Error
main.lua:73: Invalid key constant:
Traceback
[C]: in function 'isDown'
main.lua:73: in function 'update'
[C]: in function 'xpcall'
I don't know if it is intentional, but if you require tween into 2 separate local variables and do an update(dt) on one of them, both get updated.
Using one table as the metatable creates a sort of self-contained singleton hybrid.
I must consider that some people might want to use tweens with independent dts. Easy fix: add a :update method to the returned tweens. More involved solution: create / update groups of tweens.
Have encountered problems with colors:
Another topic - text seems to be handled differently than other objects:
Sure would be nice to have some documentation in 'tween' to help find out what's going on.
Nice effects but struggling to control.
Best
https://github.com/kikito/tween.lua/blob/master/tween.lua#L38 and https://github.com/kikito/tween.lua/blob/master/tween.lua#L35 have their descriptions flipped.
Hello,
It might be intentional but tween:update
doesn't return true when the tween reaches its original value when running backwards (aka passing a negative "dt").
Adding the following in Tween:set
do the trick (line 340).
return self.clock >= self.duration or self.clock == 0
Can you think of any possible side-effects if I run Tween with this hack?
Thanks
hey! I'm new to Lua, but was wondering if there's an easy way to get your tween library to just call a callback instead of applying the changes directly to a table? Perhaps the callback could have a few parameters, like:
percentComplete, delta
and percent = 0 is the start, and percent = 100 signifies the end of the tween, and returning false from the callback would cancel the tween?
I feel like I could mod the library to do this pretty easily, but was wondering what your thoughts were?
Thanks!
Here is what I get when trying to run the give example in terminal with command "lua a.lua",
lua: /usr/local/lib/lua/5.4/tween.lua:344: dt must be a number
stack traceback:
[C]: in function 'assert'
/usr/local/lib/lua/5.4/tween.lua:344: in method 'update'
...skaran/Documents/Development/LUA/a.lua:7: in main chunk
[C]: in ?
I have the following issue, I create all my tweens at startup like this:
local subject = { myVar = 0 }
local first = tween.new(2, myVar, {myVar = 200})
local second = tween.new(2, myVar, {myVar = 400})
for i=1, 4 do
local complete = first:update(dt)
if complete then second:update(dt) end
print(myVar)
end
I would expect:
100
200
300
400
But instead I get:
100
200
100
400
The problem is that since the tweens affect the same object and were created at the same time they always go back to the original state, when I just want them to "connect"
I know how the library works internally and that this is no simple change because you basically deepcopy the original table and use that as the base.
But for complex animations this is a needed feature, is this possible in a simple way?
Something like deepcopying the table on the first update of the tween
Note: Here I put two tweens but we are talking about many more, maybe a hundred, and most of them are repeated, modify really similar variables.
Should the tweens
table be a local, since it's label under the comment "private stuff"?
Tween.lua is really awesome! Great work. I usually extend it with a 'delay call' interface function like this
function tween.delay(time, callback, ...)
return tween.start(time, {}, {}, 'linear', callback, {...})
end
maybe there is a better way? Would it make sense to include this?
Is there any way to get this tween library to do a parabolic arc (like throwing a grenade)? I use this library pretty extensively in the Leadwerks engine and would love to be able to use it for a parabolic arc movement.
I used to insert if t == d then return b + c end
to solve it for my project, like following:
local function inExpo(t, b, c, d) if t == 0 then return b end if t == d then return b + c end return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001 end
But now I am really curious to know why - c * 0.001
shown in this function.
It is more like a question about why this implementation does not following others
I have an mp3 file I would like to tween. I am running Lua 5.4 and Love2d 11.3
I have the following setup in my main.lua file...
local tween = require 'libs/tween/tween'
-- increase the volume of music from 0 to 5 in 10 seconds
local music = {volume = 0, path = "audio/mp3/demo.mp3"}
local musicTween = tween.new(10, music, {volume = 5})
function love.load()
-- other code...
end
function love.update(dt)
musicTween:update(dt)
end
function love.draw()
-- other code...
end
When I run my game, there are no errors, and no sound. but the rest of the game works. what am I doing wrong?
Many thanks
local tween = require("tween")
local obj = {x = 0}
local tw = tween.new(1.5, obj, {x = 1}, "inExpo")
tw:update(1 / 40)
print("x", obj.x)
tw:update(1 / 40)
print("x", obj.x)
print:
x 9.6154344052123e-005
x 0.00023039165028796
In CSS there are not many easing curves, 5 or so. Instead it is pretty normal to use Bezier Curves to descrive a easing curve.
Bezier Curves were added to LÖVE in 0.9.0 in the love.math module (see love.math.newBezierCurve)
So I thought this would be easy to implement, and so it is! Here is my little implementation:
cubicbezier = function (x1, y1, x2, y2)
local curve = love.math.newBezierCurve(0, 0, x1, y1, x2, y2, 1, 1)
return function (t, b, c, d) return c * curve:evaluate(t/d) + b end
end
The usage with tween.lua is simple:
local label = { x=200, y=0, text = "hello" }
local labelTween = tween.new(4, label, {y=300}, cubicbezier(.35, .97, .58, .61))
I know and understand that tween.lua is not a LÖVE library but a Lua library in general, but it will be nice if this possibility would be at least documented somewhere (since it is pretty simple and nice)
PS: If you dont know what those freaking numbers are (as I was also confused at first), check this
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.