A bug or am I overlooking something?

Okay, so, for some odd reason it draws the ellipse but when the touch is ended it continues to draw the ellipse. And hen if you begin a new touch it draws both the first ellipse and one for the new touch. They never disappear, but occasionally they will start rapidly flashing. Here’s the code, please help.

function setup()
    strokeWidth(10)
    stroke(255,255,255,255)
    lasso = nil
    originid = nil
end

function draw()
    if lasso ~= nil and originid ~= nil then
    ellipse(lasso.x,lasso.y, 10,10)
    end
end

function touched(touched)
    if touched.state == BEGAN and originid == nil then
        originid = touched.id
        lasso = vec2(0,0)
        lasso.x=touched.x
        lasso.y=touched.y
    elseif touched.state == ENDED and touched.id == originid then
        lasso = nil
        originid = nil
    end
end

@Monkeyman32123 - put this line at the top of draw, to cover up the previous drawing, otherwise it stays there

background(255) --or whatever colour you want

Okay, thank you. I feel really stupid now. I’ve made like five games on this app and never really messed with that line of code and they’ve all worked perfectly, for this game I decided to start from scratch with blank functions (to get rid of the annoying codea comments), and I guess because I’d never messed with that line I was never alerted to its importance. Weird part is that objects not covered up by the background will still be affected by a per-frame color randomizer (as I just tried in another one of my experiments and discovered). Any idea why that happens?

@Monkeyman32123 Not sure what you mean, but I think you’re seeing flickering of objects when not using background()?

Codea has three buffers for the screen, to prevent flickering. First frame, you draw to the first buffer, second frame you use the second buffer, third the third buffer, and when the frame number is past three, it goes back to one, so on the fourth frame you’re drawing to the first buffer, fifth the second, etc.

If you’re not using background(), it’s best to use backingMode(RETAINED). The flickering is that you say, drew a circle in one part of the screen on the first buffer, different spot on the second buffer, and the same for the third. Then when it’s going through all the buffers, since you didn’t use background() to clear it from the last time you drew to the buffer, the circles are still there, but only in certain buffers, thus flickering every time you use that buffer with the circle on it.

backingMode(RETAINED) copies everything from the previously used buffer to the current buffer, so there’s no flickering if you’re not using background().

Never mind, the thing I was talking about in that last message was just my ipad being a bit dumb, I closed codea and reopened it and it wasn’t doing it anymore