Why does this line terminate?

If you draw zig zags or a “W” repeatedly it doesn’t take long for this to stop drawing line points. Any ideas?

It’s just the line drawing portion of the “point reduction” code available on this site.

[lua]display.setStatusBar( display.HiddenStatusBar )
_W = display.contentWidth
_H = display.contentHeight

local linePoints = {};

local FALSE = 0
local TRUE = 1
local moved = FALSE;
–local backdrop = display.newImageRect(“green_chalk_bkg.png”, 1024,768);
backdrop.x = _W/2 ; backdrop.y = _H/2
local draw;
local dragHandles;



– drag handles


local function dragHandles(event)

local phase = event.phase
if “began” == phase then
– Make target the top-most object

local pt = {}
pt.x = event.x;
pt.y = event.y;
table.insert(linePoints,pt);
elseif “moved” == phase then
local pt = {}
pt.x = event.x;
pt.y = event.y;
table.insert(linePoints,pt);
moved = TRUE;
elseif “ended” == phase or “cancelled” == phase then
moved = FALSE;
–polySimplify(linePoints,40);
for i,v in ipairs(linePoints) do print(i,v) end
end

return true

end


– drawline


local function drawLine()

if ( moved == FALSE ) then return; end

if ( line ) then line:removeSelf() end

if #linePoints > 2 then
line = display.newLine(linePoints[1].x,linePoints[1].y,linePoints[2].x,linePoints[2].y);
for i = 3, #linePoints, 1 do
line:append(linePoints[i].x,linePoints[i].y);
end
line:setColor(255,255,0);
line.width=12
end

end


local function draw (event )
if ( moved == TRUE ) then
drawLine()
return true;
end
end



local function main()
Runtime:addEventListener(“touch”,dragHandles);
Runtime:addEventListener(“enterFrame”,draw);
end



main();[/lua] [import]uid: 10361 topic_id: 11915 reply_id: 311915[/import]