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]