display.newLine doesn't display new line

I’m drawing to the screent during touch events using display.newLine. There seems to be a bug (or just something I don’t understand) that prevents the line from being displayed onscreen until a new display.newLine is called.

local line

local function draw(event)
 if(event.phase == "moved") then
 if not line then
 line = display.newLine(event.xStart, event.yStart, event.x, event.y)
 end
 line:append(event.x, event.y)

 -- Here comes the wonky part
 -- Without this, the line won't appear onscreen 
 -- until I lift my finger from the screen and touch again

 display.newLine(0,0,0,0):removeSelf() 
 elseif(event.phase == "ended") then
 line = nil
 end
end

Runtime:addEventListener("touch", draw)

This behavior doesn’t occur with other vector shapes. The shapes created by newRect and newCircle appear immediately, as expected. [import]uid: 41243 topic_id: 7540 reply_id: 307540[/import]

read this…
http://developer.anscamobile.com/forum/2010/12/15/displaylineappend-doesnt-work-realtime-unless-linewidth-set-eg-linewidth00000001

follow carlos’ method [import]uid: 6645 topic_id: 7540 reply_id: 27584[/import]

Thanks for the pointer.

There is another issue that I had been dealing with that still happens with Carlos’ code, though. Lines stop drawing if you change the direction of your touch in a certain way. I know the code is running because I can still get print statements from the event handler, but no lines are displayed after making a 180 degree reversal in direction. Touch and drag straight up and all is good until you begin to drag straight down. Same with horizontal lines. It keeps working as long as you don’t head back exactly the way you came.

I haven’t tested that behavior with other vector objects, but I wouldn’t be surprised if they worked fine. newLine seems to be the odd object out on several fronts. [import]uid: 41243 topic_id: 7540 reply_id: 27876[/import]