user3871981
user3871981

Reputation: 23

Fade text color in Corona SDK

I have a list of color codes and want to make a text fade the colors smoothly like in this picture:

Fading colors

Is this possible with Corona? I couldn't find a way to do this yet.

Upvotes: 1

Views: 397

Answers (1)

Teddy Engel
Teddy Engel

Reputation: 1006

Try this function I made, might not be perfect but it works for me:

-- Transitions a display object from one color to another (based on 0 to 1 values)
function applyColorTransition(oDisplayObject, nDelay, nStartR, nEndR, nStartG, nEndG, nStartB, nEndB)
    if oDisplayObject.setFillColor then

     local nIterations = 10
     local nStepsR = (nEndR - nStartR) / nIterations
     local nStepsG = (nEndG - nStartG) / nIterations
     local nStepsB = (nEndB - nStartB) / nIterations
     local nI = 1
     timer.performWithDelay( nDelay, function()
            oDisplayObject:setFillColor(nStartR + nStepsR * nI, nStartG + nStepsG * nI, nStartB + nStepsB * nI)
        nI = nI + 1
     end, nIterations)
    end
end

Upvotes: 2

Related Questions