Clone wiki

Core / tint

Back to Beyond the Codea in-app reference

FunctionIconFunction-Small.png tint() function


Codea's in-app reference documents the tint() function. Each pixel of an image drawn by the sprite(image, ...) function is multiplied by the colour set as the tint (including the alpha channel):

tint(r1, g1, b1, a1)

-- (r, g, b, a) -> (r * r1/255, g * g1/255, b * b1/255, a * a1/255)

Default tint()

The default tint() is equivalent to tint(255, 255, 255, 255) (opaque white). For example:

print(tint()) -- Outputs: 255     255     255     255

tint() and the alpha channel

Setting a tint with an alpha channel less than the maximum of 255 will make a sprite semi-transparent. This can be used to fade in, or fade out, images. For example:

function setup()
    myImage = readImage("Planet Cute:Icon")

function draw()
    local alpha = math.min(ElapsedTime * 10, 255) -- Alpha channel has a maximum of 255
    tint(255, alpha)                              -- Set tint using tint(grey, alpha)
    sprite(myImage, WIDTH/2, HEIGHT/2)            -- Draws myImage applying tint