gre.animation_create_tween

gre.animation_create_tween(name, tween_callback)
                    

Create a new animation tweening (interpolation) function that can be used by both Lua and Animation Timeline animations. The name of the tweening function cannot collide with any existing animation tweening names. The callback function is a generic tween function that will be provided with specific parameters outlining the desired range of the values being tweend and the frame at which the values should be interpolated.

The tweening function is called with four parameters elapsed, base, change, duration. The elapsed value indicates the interpolation location and is in the range from [0,duration] so if one wanted to derive the percentage that the animation has completed, it would be elapsed/duration. The base value represents the numeric starting point of interpolation and the end point of the animation will be base+change. These four values can be applied to various transforms to return a single floating point value that represents the desired outcome of the interpolation function at that point in time. The output of the interpolation is clamped to the range [base,base+change] though this restriction may be lifted in future releases of Storyboard.


Parameters:
        name     The name to use for the tween operation, it is case sensitive and must not collide with
                        other tween names
        tween_callback  The callback function to be invoked when an animation using the named tween function is
                        invoked
        
Returns
        true on successful registration

Example:        

-- Re-implemented linear tween
local function CustomTweenCB(elapsed, base, change, duration)
    return base + ((change * elapsed) / duration)
end

-- This is called at application initialization to register the custom
-- tween function
function CBRegisterTween(mapargs)
    gre.animation_create_tween("MyTween", CustomTweenCB)
end

-- Create an animation that fades out a layer and uses the custom
-- tween function
function CBAnimation(mapargs)
    local id = gre.animation_create(60)

    local data = {}
    data["rate"] = "MyTween"
    data["duration"] = 2000
    data["offset"] = 0
    data["from"] = 255
    data["to"] = 0
    data["key"] = "MyScreen.MyLayer.grd_alpha"
    gre.animation_add_step(id, data)

    gre.animation_trigger(id)
end