I have wrote very inefficient code to draw and follow line as below
local tale={} local c=0 local xc,yc,w,h=display.contentCenterX,display.contentCenterY,display.contentWidth,display.contentHeight local blue=display.newRect(xc,yc+300,160,160) blue:setFillColor( 1,0,1 ) local function play(id) transition.to( blue,{x=tale[id].x,y=tale[id].y,time=100,onComplete=function() c=c-1 if c\>0 then play(id+1) end end}) end local function start(event) play(1) return true end local function draw(event) local xa=display.newCircle(event.x,event.y,20) xa:setFillColor( 0,1,1 ) c=c+1 table.insert( tale,c,xa) end local x=display.newRect(xc,yc,100,100) x:setFillColor( 1,0,0 ) local bg=display.newRect(xc,yc,10000,10000) bg:setFillColor( 0,1,0 ) x:toFront() bg:addEventListener( "touch", draw ) x:addEventListener( "touch",start ) blue:toFront( ) --Touch screen to draw..touch red to start
It is very inefficient and doesn’t work as expected…
How to make a line follower efficiently??