Drawing a line flaws (Help Please)

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)

Please put your code in Lua tags; I've asked you this before. Use the tags so it is readable and not headache inducing! Very important!

Also, I'm moving this to Developer Support; Off Topic is only for Off Topic threads.

Split your code into two parts.
Part 1. Keep the touch event but just have it add each new touch point to a table.
Part 2. Create an enterFrame listener that redraws the line each frame based on the points in the above table.

How can we put them in lua code?

< lua > and < / lua > without the spaces, as mentioned in the guidelines.

i did play around with this code a bit and stripped out the physics bit focussing on the line bits only.

The line code just works ok..although i think the . before remove should be :remove?

1
2
3
tempLine.parent.remove(tempLine) 
-- should be
tempLine.parent:remove(tempLine) 
views:1389 update:2011/9/29 9:22:17
corona forums © 2003-2011