Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

screen keeps redrawing sprite (in various locations)

edited September 2012 in Bugs Posts: 66

I'm working on a page-turning routine -- and the code drawing the turning page goes into a mad redrawing loop even when it should stop.

(It draws the sprite at the finger touch location)

Code follows -- simplified to show the problem. Any ideas what the problem is?
Thanks

-- test
    displayMode(FULLSCREEN)
-- Use this function to perform your initial setup
function setup()     
    spriteMode(CORNER)
    backingMode(STANDARD)
    tp=0
    lastDelta=0
    midX=WIDTH/2

    current= image(WIDTH,HEIGHT) 

    setContext(current)
    sprite("Cargo Bot:Codea Icon",0,0,WIDTH,HEIGHT)
    setContext()
    pager = image(WIDTH/2,HEIGHT)    
    pager=current:copy(WIDTH/2,0,WIDTH/2+1,HEIGHT) 


end

function touched(touch)
    if CurrentTouch.state == BEGAN or
       CurrentTouch.state == MOVING then
        lastDelta = CurrentTouch.deltaX*-1
        tp=CurrentTouch.x
        end

end



function drawPage()
    if tp>midX then
        sprite(pager,midX,0,tp-midX,HEIGHT)
    elseif tp>0 then
        sprite(pager,tp,0,midX-tp,HEIGHT)
        end

    end


function draw()
    drawPage()
    end

Comments

  • Posts: 892

    Add

       background(0,0,0)
    

    between function draw() and drawPage()

  • Posts: 66

    thanks -- that worked.

    But What caused the problem? specifically the random redrawing? I assumed backingMode(STANDARD) would start with a blank buffer -- but I'm guessing it only assumes the code is responsible for display buffer updates -- and the "random" redraws was really buffermemory artifacts?

  • SimeonSimeon Admin Mod
    edited September 2012 Posts: 5,708

    .@akiva that is correct. The standard backing mode assumes that the screen will be cleared before draw. We could do this automatically but it's less optimal in the case where you completely fill the screen each frame. Perhaps we still should do this automatically when standard backing mode is used.

  • Posts: 66

    Hi Simeon. Thanks for the clarification. You might want to mention this in the docs.

    Why not make it an optional flag? I.E. backingMode(STANDARD,BLANK) would zero out the background (Or make BLANK a color value), while backingMode(STANDARD) wouldn't.

  • SimeonSimeon Admin Mod
    edited September 2012 Posts: 5,708

    That's a good idea about adding a new backingMode. Perhaps we'll do the opposite in terms of parameters, though:

    backingMode(STANDARD) always clears, whereas backingMode(NO_CLEAR) lets you handle clearing.

Sign In or Register to comment.