Polyline and touch events

I am trying to put together some code to extend a polyline depending on where the user touches. Below is a stripped down version of the code I’ve put together. If I “manually” call myline:touch (lines 20-22) it extends the polyline. If I call myline:touch from a touch event handler, it does not draw. The print statement on line 17 indicates that the function is being called, but it’s not drawing.

I’d appreciate it if you can spot what I’m overlooking,

Matt

myline = {}  
  
myline.x0 = display.contentWidth/2  
myline.y0 = display.contentHeight/2  
  
myline.x1 = myline.x0 + 3  
myline.y1 = myline.y0 + 3  
  
myline.line0 = display.newLine(myline.x0, myline.y0, myline.x1, myline.y1)  
myline.line0:setColor(255, 0, 0, 255)  
myline.line0.width = 4  
  
function myline:touch(event)  
 self.x0, self.y0 = self.x1, self.y1  
 self.x1, self.y1 = event.x,event.y  
 print('appending to ' .. self.x1 .. ', ' .. self.y1)  
 self.line0:append(self.x1, self.y1)  
end  
  
myline:touch { x = 10, y = 300 } -- works  
myline:touch { x = 310, y = 20 } -- works  
myline:touch { x = 10, y = 10 } -- works  
  
Runtime:addEventListener( "touch", myline) -- doesn't work  

[import]uid: 78 topic_id: 2207 reply_id: 302207[/import]

Hi Matt,

I found a related forum post here involving line:append():

http://developer.anscamobile.com/forum/2010/06/26/bug-using-displaynewline#comment-3486

It appears that append() doesn’t do what you would expect after the line has been rendered. The solution in that case was to re-draw the entire line (from an internal table representation) on each “move” touch event. Not ideal, I know.

I filed case 1251 to investigate this issue, and 1252 to update the Polyline docs.

thanks,
Tim
[import]uid: 8196 topic_id: 2207 reply_id: 6739[/import]

Ok, clearly I didn’t search carefully enough. Thanks for tracking this down.

Matt
[import]uid: 78 topic_id: 2207 reply_id: 6777[/import]