Eraser

Hello,

I am using this code to draw a line. I am also trying to make an eraser, is this possible? When the eraser goes over the line it deletes it.

[lua]local i = 1
local tempLine
local ractgangle_hit = {}
local prevX , prevY
local function runTouch(event)
if(event.phase==“began”) then
if(tempLine==nil) then
tempLine=display.newLine(event.x, event.y, event.x, event.y)
tempLine:setColor(255,255,255,255)
tempLine.width=5
prevX = event.x
prevY = event.y
end
elseif(event.phase==“moved”) then
tempLine:append(event.x,event.y-2)
tempLine.width=tempLine.width+0.000001
ractgangle_hit[i] = display.newLine(prevX, prevY, event.x, event.y)
ractgangle_hit[i]:append(event.x,event.y)
ractgangle_hit[i].width=2
ractgangle_hit[i].alpha = 0

local Width = ractgangle_hit[i].width * 0.3
local Height = ractgangle_hit[i].height * 0.3
local lineShape = {-Width,-Height,Width,-Height,Width,Height,-Width,Height}

physics.addBody(ractgangle_hit[i], “static”, { density=0.3, friction=0.7, shape = lineShape})
prevX = event.x
prevY = event.y
i = i + 1
elseif(event.phase==“ended”) then
tempLine.parent.remove(tempLine)
tempLine=nil
end
end
Runtime:addEventListener(“touch”, runTouch)[/lua]
Thank you.

*Edited: Please use Lua tags when pasting code so that it is easy for everyone to read. [import]uid: 66985 topic_id: 10868 reply_id: 310868[/import]

@theCardMagicien,
you will have to test if the point of touch is overlapping with the line, if it is, then you can remove that line. For which you will have to hold all the objects/coordinates in an array/table to check against.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 10868 reply_id: 39541[/import]