I found this beautiful function that allows me to draw a line on the screen with your finger, I’m trying to figure out how to make the line lose its event Listener if it touches itself, a collision. So if you drew a circle and touched the line you are drawing together it would stop drawing from the line colliding with itself. Here is the function, thanks for the help!
[lua]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(math.random(255), math.random(255), math.random(255))
tempLine.name = ‘tempLine’
group:insert(tempLine)
prevX = event.x
prevY = event.y
end
elseif(event.phase==“moved”) then
tempLine:append(event.x,event.y-2)
tempLine.width=tempLine.width+.9
ractgangle_hit[i] = display.newLine(prevX, prevY, event.x, event.y)
ractgangle_hit[i]:setColor(math.random(255), math.random(255), math.random(255))
ractgangle_hit[i].width = 2
ractgangle_hit[i].name = ‘ractgangle_hit[i]’
group:insert(ractgangle_hit[i])
– Creates physic joints for line (Turn on draw mode to see the effects)
local Width = ractgangle_hit[i].width * 0.6
local Height = ractgangle_hit[i].height * 0.2
– Physic body for the line shape
lineShape = {-Width,-Height,Width,-Height,Width,Height,-Width,Height}
lineShape.name = ‘lineShape’
physics.addBody(ractgangle_hit[i], “static”, { bounce = 0, density=0.9, 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
Runtime:removeEventListener(“touch”, runTouch)
end
end
Runtime:addEventListener(“touch”, runTouch) [import]uid: 75779 topic_id: 29705 reply_id: 329705[/import]