Blinking sprites

When I try this code, it makes the sprites move across the screen and deletes them when they get to the bottom, but when they are deleted from the table, it makes all the other sprites on the screen blink, and I don’t want that

displayMode( FULLSCREEN)
supportedOrientations(CurrentOrientation)

function setup()
    dy=-5
    count=0
    loc={342, 433, 523, 608, 703}
    car={}
    car1={}
    table.insert(car, "Planet Cute:Character Boy")
    table.insert(car, "Planet Cute:Character Cat Girl")
    table.insert(car, "Planet Cute:Character Horn Girl")
    table.insert(car, "Planet Cute:Character Pink Girl")
    table.insert(car, "Planet Cute:Character Princess Girl")
    next()
end

function next()
    x = math.random(1,5)
    s = math.random(1,5)
    table.insert(car1,vec3(s,x,HEIGHT))
end

function draw()
    background(52, 172, 22, 255)
    for a,b in pairs(car1) do
        sprite(car[b.x],loc[b.y],b.z)
        b.z=b.z+dy
        if b.z<0 then
            table.remove(car1,a)
            return
        end
    end
    count=count+1
    if count>50 then
        next()
        count=0
    end
end

Try replacing:

    for a,b in pairs(car1) do
        sprite(car[b.x],loc[b.y],b.z)
        b.z=b.z+dy
        if b.z<0 then
            table.remove(car1,a)
            return
        end
    end

With

for i=#car1,1,-1 do
        sprite(car[car1[i].x],loc[car1[i].y],car1[i].z)
        car1[i].z=car1[i].z+dy
        if car1[i].z<0 then
            table.remove(car1,i)
            --return
        end
    end

This works because when you were drawing the sprites you drew them from first to last. But when you used table.remove() all the sprites after the one you had just removed were shifted down one place in the table so it would skip some. For example: if you remove the first car then all the others are shifted in place down so 2nd becomes 1st, 3rd becomes 2nd etc… But then you go on to draw the second item, which was the 3rd before you deleted the first item so you have skipped the second item(now the 1st). However if you draw them from last to first you are unaffected by this problem. Sorry for not explaining this very well. I hope it works

Thanks

No problem