Drawing / Eraser

I have this code to draw and it works, however the function to erase not
Someone I can help please?

--Drawing math.randomseed( os.time() ) local object = display.newImage( "caneta2.tif" ) object.id = "ball object" local function onObjectTouch( event ) if ( event.phase == "began" ) then local lineTable = {} -- This is a required table that will contain each drawn line as a separate display group, for easy referral and removal local lineWidth = 12 local lineColor = {R=math.random(0,255), G=math.random(0,255), B=math.random(0,255)} local newLine = function(event) local function drawLine() local line = display.newLine(linePoints[#linePoints-1].x,linePoints[#linePoints-1].y,linePoints[#linePoints].x,linePoints[#linePoints].y) line:setColor(lineColor.R, lineColor.G, lineColor.B); line.width=lineWidth; lineTable[i]:insert(line) local circle = display.newCircle(linePoints[#linePoints].x,linePoints[#linePoints].y,lineWidth/2) circle:setFillColor(lineColor.R, lineColor.G, lineColor.B) lineTable[i]:insert(circle) end if event.phase=="began" then i = #lineTable+1 lineTable[i]=display.newGroup() display.getCurrentStage():setFocus(event.target) local circle = display.newCircle(event.x,event.y,lineWidth/2) circle:setFillColor(lineColor.R, lineColor.G, lineColor.B) lineTable[i]:insert(circle) linePoints = nil linePoints = {}; local pt = {} pt.x = event.x; pt.y = event.y; table.insert(linePoints,pt); elseif event.phase=="moved" then local pt = {} pt.x = event.x; pt.y = event.y; if not (pt.x==linePoints[#linePoints].x and pt.y==linePoints[#linePoints].y) then table.insert(linePoints,pt) drawLine() end elseif event.phase=="cancelled" or "ended" then display.getCurrentStage():setFocus(nil) i=nil end return true end local erase = function() for i = 1, #lineTable do lineTable[i]:removeSelf() lineTable[i] = nil end return true end Runtime:addEventListener("touch",newLine) elseif ( event.phase == "ended" ) then display:remove( line ) display:remove( circle ) end return true end object:addEventListener( "touch", onObjectTouch ) --Eraser local object2 = display.newImage( "logo.png" , 100,100 ) object2.id = "ball object" local function onObjectTouch1( event ) if ( event.phase == "began" ) then elseif ( event.phase == "ended" ) then return true end end object2:addEventListener( "touch", onObjectTouch1 )

Someone ? No, ok :frowning: :frowning:

Hi David. One of the reasons you’ve not gotten an answer is the post isn’t providing enough information. People viewing the post see a lot of code and a very vague description of a problem. I recommend you take the time to completely read this post:

https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

Then come back and re-ask your question following @roaminggamer’s suggestions. A better title will get more views. A better description of the problem, what you’re seeing, what you expect will go a long way to getting you responses.

With this post as it is, anyone (including me) will have to spend time asking you questions to figure out what’s going on. You should be able to edit the title and the top/first post with better details.

Thanks

Rob

Someone ? No, ok :frowning: :frowning:

Hi David. One of the reasons you’ve not gotten an answer is the post isn’t providing enough information. People viewing the post see a lot of code and a very vague description of a problem. I recommend you take the time to completely read this post:

https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

Then come back and re-ask your question following @roaminggamer’s suggestions. A better title will get more views. A better description of the problem, what you’re seeing, what you expect will go a long way to getting you responses.

With this post as it is, anyone (including me) will have to spend time asking you questions to figure out what’s going on. You should be able to edit the title and the top/first post with better details.

Thanks

Rob