It looks like you're new here. If you want to get involved, click one of these buttons!
I just noticed on the wiki page for Codea's Tween API that we can write our own easing functions for Tween.
This is the template from the wiki page:
-- t is the current time
-- d is the duration of the animation
-- b is the initial animated value
-- c is the change in the animated value by the end of the animation
function myEasing(t, b, c, d)
local result
... -- Code to calculate result
return result
end
It seems to be fairly close to this: https://github.com/kikito/tween.lua
What I wanted to ask is, would it also be possible to write a tween looping function in a similar way? Specifically I would like to write a pingpong.once
function. If so, what would the template look like? (It'd be great if we could see the source for the existing pingpong
function, assuming it is implemented in Lua)
Comments
i know it is not exactly what you ask for, but just in case you only need a pingpong once function, try this:
@Jmv38 Wow, that is very clever.
^:)^
Thank you!
This is easier for me to understand and does the same thing.
i agree
@Jmv38 Actually, it can be shortened by eliminating p3 and just reusing p1 in the tween.path since we're going back to the starting point.
@dave1707 I keep forgetting about
tween.path
... I'm experimenting with it now. Although maybe atween.sequence
might be closer to apingpong.once
aspath
adds a splineThis is slightly off-topic, but one thing that I think is odd about tweens is that when they're called as part of a class, and you want the callback to be a function of that class, you have to wrap it in an anonymous function. ie:
It just seems slightly wasteful, given that advice on optimising Lua recommends not repeatedly creating closures:
http://lua-users.org/wiki/OptimisationCodingTips
Or are repeated anonymous functions (ie you have lots of tweens firing at once) not such an issue performance wise? Am I worrying unnecessarily here?
@yojimbo2000 it's necessary in order to bind
self
to the function. If you wrote your function as a static method (i.e., no access toself
) then you could just pass the function name.@Simeon and is it possible to add our own looping functions, like we can with easing?