Hey,
In my game there the user needs to draw a line, which a ball rolls down. I've been using this code for a long time but there are many flaws. For some reason when you swipe through the screen the line sometimes does not show up, but in draw mode it shows. There is 1/10 times that this code des not work properly. Even as you try to draw the line there is no visible line shown. Sometimes it is shown if you turn on draw mode. If there are any better ways to have the user draw a line please inform me !
I really need help !
Thank you very much! Help is very appreciated!
Try using this coe for a bit and you will know what i mean!
Draw a line code :
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=4
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", { bounce = -1, 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)