Final note.
If you want to store the vertex info in the line do this:
-- May have typos local function getVerts( self ) return self.myVertices end local function getLength( self ) local len = 0 -- Your job to figure this out -- iterate over my vertices and calculate length return len end local function getPercentPosition( self ) local x,y = 0,0 -- Calculate x,y position as % of length -- Your job to figure this out -- SSK2 has tools you need to do this. return x,y end local display\_newLine = display.newLine function display.newLine( ... ) local line = display\_newLine( unpack( arg ) ) local verts = {} line.myVertices = verts line.getVerts = getVerts line.getLength = getLength line.getPercentPosition = getPercentPosition local start = (type(arg[1]) == "table") and 2 or 1 for i = start, #arg, 2 do local vert = {} verts[#verts+1] = vert vert.x = arg[i] vert.y = arg[i+1] end local lappend = line.append function line.append( ... ) lappend( unpack( arg ) ) for i = 1, #arg, 2 do local vert = {} verts[#verts+1] = vert vert.x = arg[i] vert.y = arg[i+1] end end return line end
Now later…
local aLine = newLine( 100, 100, 120, 100, 140, 100, 150, 150 ) print( aLine:getLength() ) local verts = aLine:getVerts() local x,y = aLine:getPercentPosition( 0.60 )