Image opacity

I want to create slideshow type cutscenes, and I was working on creating a crossfade effect. To make it work I need to layer images and cause the one on top to become more and more transparent.

I wrote some code that uses “get” to grab each pixel, modify its alpha, then uses “set” to put it back. You can imagine that this is fairly slow and looks less than smooth. Anyone have any idea how to modify the alpha of an entire image? I was trying to figure out some way to do it with meshes too but haven’t come up with anything.

When the texture of a mesh is tinted by the colour of its vertices, does that apply equally to the alpha component of the vertex colour?

The answer is Yes, as shown by the example below:


function setup()
    myMesh = mesh()    
    idx = myMesh:addRect(100, 100, 200, 200)
    myMesh.texture = readImage("Planet Cute:Icon")
    myMesh:setRectTex(idx, 0, 0, 1, 1)
end

function draw()
    background(40, 40, 50)
    myMesh:setColors(255, 255, 255, math.min(ElapsedTime * 10, 255))
    myMesh:draw()
end

However, why use a mesh when you can tint an image directly? For example:


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

function draw()
    background(40, 40, 50)
    tint(255,255,255,math.min(ElapsedTime * 10, 255))
    sprite(myImage, WIDTH/2, HEIGHT/2)
end

Thanks, @mpilgrem. I should have figured that out. I guess I didn’t realize that tint worked that way.