How to detect "lines" drawn and set them to nil ?

Hey all,

Im using this code that I got from the online example.

function drawLine( event )
if(event.phase == “ended”) then
line = display.newLine(event.xStart, event.yStart, event.x, event.y)
line:setColor(255,0,0)
line.width = 5
end
end
Runtime:addEventListener(“touch”, drawLine)
When you press and move your cursor and then release
a line is drawn.

Now with it being drawn, how do i destroy it ?

Is there a Table of the LINES/events that are DRAWN on the screen ?

Thanks in advance :slight_smile:
[import]uid: 11094 topic_id: 15790 reply_id: 315790[/import]

even a line of width 5 is quite a challenge to touch, however, you can in the eraser mode get a point and check if the point is in any of the lines you have in the array. If it is, then that’s the line you need to erase.

Oh, you also asked if there is a table of lines, no there isn’t, why don’t you create one? so just add to your code

  
linesArray = {}  
  
function drawLine( event )  
 if(event.phase == "ended") then  
 line = display.newLine(event.xStart, event.yStart,  
 event.x, event.y)  
 line:setColor(255,0,0)  
 line.width = 5  
  
 linesArray[#linesArray+1] = line  
  
 end  
end  
  
Runtime:addEventListener("touch", drawLine)  
  

now you have linesArray as a table that holds all the lines you drew.

?:slight_smile: [import]uid: 3826 topic_id: 15790 reply_id: 58330[/import]

dude !

Thanks for that easy peasy code !!!

i really appreciate the nudge.

thank :slight_smile: [import]uid: 11094 topic_id: 15790 reply_id: 58648[/import]