tween.lua

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

tween.lua

Post 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
Attachments
tween-font-demo.love
(71.21 KiB) Downloaded 724 times
Last edited by kikito on Thu Apr 26, 2012 12:08 am, edited 1 time in total.
When I write def I mean function.
User avatar
Trappingnoobs
Citizen
Posts: 95
Joined: Tue Oct 12, 2010 8:52 pm

Re: tween.lua

Post by Trappingnoobs »

Wow; that looks great. I like the fact you've got so many easing styles, and it looks realy easy to use.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: tween.lua

Post 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)
When I write def I mean function.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: tween.lua

Post by T-Bone »

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: tween.lua

Post by kikito »

I added the font effects demo that I created in another post to the OP of this thread.
When I write def I mean function.
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: tween.lua

Post by Zeliarden »

This is cool!
tween synced with anim8?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: tween.lua

Post 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.
Last edited by kikito on Sat Apr 28, 2012 1:13 pm, edited 1 time in total.
When I write def I mean function.
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: tween.lua

Post 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
Attachments
Tween Test.love
(15.03 KiB) Downloaded 535 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: tween.lua

Post 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?
When I write def I mean function.
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: tween.lua

Post by Zeliarden »

the function call is inCirc, outCirc, inOutCirc, outInCirc instad of inCircle, outCircle, inOutCircle, outInCircle
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests