Wiki

Clone wiki

Core / tween

Back to Beyond the Codea in-app reference


FunctionIconOverview-Small.png tween API

Introduction

The 'Animation' chapter of Codea's in-app reference documents most of the tween API, which is implemented in Lua as a table. The API allows variables to be animated from an initial value to a target value over a period of time using a built-in or user-defined easing function.

tween()

The metatable of tween is set so that it can be called like a function. The function returns a table which contains the following fields:

myTween = tween(time, subject, target, easing, callback, arg1, arg2, arg3)
myTween.time    -- the time period of the tween
myTween.running -- the current point in the time period of the tween
myTween.initial -- a table (the initial state of the subject)
myTween.subject -- the table that is the subject of the tween
myTween.target  -- the table that is the target of the tween
myTween.easing  -- the easing function of the tween
myTween.args    -- a table (the optional arguments to the callback function)
myTween.loop    -- a function (tween.loop.once, by default)

Built-in easing functions

Codea's in-app reference documents the built-in easing functions, with the exception of the circ series of functions: circIn, circOut, circInOut} and circOutIn.

User-defined easing functions

A user-defined easing function has the following form:

-- 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

Updated