Monkeypatch for the tweening library known as flux created by rxi for love2d.
Twn adds __call-metamethods to the flux-module and to the objects created by it. The goal of Twn is to reduce the amount of syntax needed for creating tweens with flux.
Twn will not alter the existing functionality of the flux-module.
Twn assumes that flux is required to a variable "flux".
flux = require 'flux'
require 'twn'
Previously used.
flux.to(object, time, changes)
Can now be alternatively accomplished like this.
flux(object, time, changes)
Easing can be set as an optional argument.
flux(object, time, easing, changes)
Tweens can be chained effortlessly by adding more arguments.
flux(object1, time1, ease1, changes1, object2, time2, ease2, changes2) --... and so on
Only the first object argument is mandatory. Following tweens will assume the that same object is used if the object argument is missing. If the easing-argument is left out "linear" will be used. This is an inconsistency with the flux.to-function that defaults to "quadout".
--start with "linear" end with "quadout"
flux(object, time1, changes1, time2, "quadout", changes2) --... and so on
To help sequence tweens Twn provides set-method that can be used to store the returned object to global scope or to a provided table.
--endless chain of tweens can also include assignments
flux(object1, time1, changes1):set("global_variable")(time2, changes2):set("field", table)
global_variable(time3, changes3, "quadout")
table.field(object2, time4, changes4)
flux = require 'flux'
require 'twn'
love.load = function()
circle = {x = 100, y = 100, r = 10}
flux(circle, 1, {x = 200, y = 200}):set("step_one")(
1, "elasticout", {y = 300},
1, "quadout", {x = 300})
step_one(4, "elasticinout", {r = 100})
end
love.update = function(dt)
flux.update(dt)
end
love.draw = function()
love.graphics.circle("fill", circle.x, circle.y, circle.r)
end