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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | 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(); |