Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A colour transition function for CoronaSDK in lua
function TransitionColor(displayObj, params)
if(params and params.startColor and params.endColor) then
local length = params.time or 300
local startTime = system.getTimer()
local easingFunc = params.transition or easing.linear
local function colorInterpolate(a,b,i,t)
colourTable = {
easingFunc(i,t,a[1],b[1]-a[1]),
easingFunc(i,t,a[2],b[2]-a[2]),
easingFunc(i,t,a[3],b[3]-a[3]),
}
if(b[4] and a[4]) then
easingFunc(i,t,a[4],b[4]-a[4])
end
return colourTable
end
displayObj.runFunc = function(event)
local runTime = system.getTimer()
if(startTime + length > runTime) then
displayObj:setFillColor(unpack(colorInterpolate(params.startColor, params.endColor, runTime-startTime, length)))
else
-- do it one last time to make sure we have the correct final color
displayObj:setFillColor(unpack(params.endColor))
Runtime:removeEventListener("enterFrame", displayObj.runFunc)
end
end
Runtime:addEventListener("enterFrame", displayObj.runFunc)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.