Page 1 of 4

tween.lua

Posted: Sun May 08, 2011 11:28 pm
by kikito
I've created another library!

I'm calling it tween.lua . It's available here:

https://github.com/kikito/tween.lua

"tweening" is an animation tecnique consisting on "interpolating" from one initial value to a 'target'. The way in which you approach that target may be defined via an easing function.

Here's a sample .love file:
tweendemo.love
(3.99 KiB) Downloaded 1161 times
And here's some basic usage sample code:

Code: Select all

tween = require 'tween'

function love.update(dt)
  ...
  tween.update(dt)
  ...
end

function love.load()
  hero = {x=100, y = 200}
  tween(4, hero, {x=200}) -- move the hero 100 pixels to the left, in 4 seconds
end
This is just a sneak peek, you may find more documentation on the project's page on github.

Notice that tween is a "callable table" (some people call them functables). tween(...) is a shortcut to tween.start(...).

Thanks a lot to Emmanuel Oga for providing with the easing functions!

Regards!

EDIT: BlackBulletIV pointed out some embarrassing privacy issue on the library (one variable was global instead of local). I've fixed this on the library and on the demo.
EDIT2: Added a new demo with font effects

Re: tween.lua

Posted: Sat Jul 23, 2011 12:25 pm
by Trappingnoobs
Wow; that looks great. I like the fact you've got so many easing styles, and it looks realy easy to use.

Re: tween.lua

Posted: Sun Jul 24, 2011 7:42 pm
by kikito
Thanks for your comments. I must point out that the easing functions came from Emmanuel Oga's easing library (I just made some adjustments)

Re: tween.lua

Posted: Mon Jul 25, 2011 2:54 pm
by T-Bone

Re: tween.lua

Posted: Thu Apr 26, 2012 12:09 am
by kikito
I added the font effects demo that I created in another post to the OP of this thread.

Re: tween.lua

Posted: Sat Apr 28, 2012 7:05 am
by Zeliarden
This is cool!
tween synced with anim8?

Re: tween.lua

Posted: Sat Apr 28, 2012 9:08 am
by kikito
You can use tween with anim8, if that's what you are asking - for example, a walking enemy could turn invisible by gradually changing its alpha with tween. This would also modify their position with tween, while their animation goes on with anim8.

I guess you could also change the "animation speed" if you modified the dt that you pass to anim8's update() method with a tween. But you would need a decent amount of frames to make it noticeable.

Re: tween.lua

Posted: Sat Apr 28, 2012 11:25 am
by Zeliarden
I mean sync their timers or something like that :P . Anyways here is a tween test I made. btw check Circle and outInElascit in the README.textile

Re: tween.lua

Posted: Sat Apr 28, 2012 1:38 pm
by kikito
I mean sync their timers or something like that :P
Well, if you use them the normal way (just passing them dt in love.update) they will be syncronized, wouldn't they? :P But really, that's what I meant on my previous phrase. You can't really syncronize a tween with an animation, but you can sync it with its speed, which is pretty much the same. The thing is that you would have to do this with separate variables. Something like this:

Code: Select all

function love.load()
   a = {speed=1}
   tween(5, a, {speed=2}) -- increase the animation speed 2x in 5 seconds
   anim = anim8(...) -- create a regular animation
end

function love.update(dt)
  tween.update(dt)
  anim:update(dt * a.speed) -- update animation with a variable speed
end
Anyways here is a tween test I made
Hey, how cool is that! :D I like the pink guy. It looks weirdly familiar.
btw check Circle and outInElascit in the README.textile
Thanks! I changed outInElascit to outInElastic. What is the problem with Circle?

Re: tween.lua

Posted: Sat Apr 28, 2012 1:55 pm
by Zeliarden
the function call is inCirc, outCirc, inOutCirc, outInCirc instad of inCircle, outCircle, inOutCircle, outInCircle