## Need help combining 2 functions

No replies
russm305 Offline
Joined: 12 Jul 2011

I have a function that allows the user to draw a line on the screen. I now want to have an "instructions" screen that will show a picture of a finger drawing the same line. The function for the finger moving is simple:

 ```1 2 3 4 5 6 7 8 9 ``` ```local function touchMove()         local touchme= display.newImageRect('finger.png',30 ,38)         touchme.x = 25         touchme.y = 120         group:insert(touchme)         transition.to(touchme,{ time = 10000, x= w-45, y= h+20})         end touchMove() ```

The function for the line drawing is a bit more sophisticated. The line, when drawn, will have "static" physics capabilities enabling balls to bounce off of it. Here it is:

 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ``` ```function runTouch(e)         if e.phase == "began" then         prev_x = e.x         prev_y = e.y           elseif e.phase == "moved" then                                          lines[line_number] = display.newLine(prev_x, prev_y, e.x, e.y)                                 lines[line_number]:setColor(math.random(255), math.random(255), math.random(255))                                 lines[line_number].width = line_width                                 group:insert(lines[line_number])                                 dist_x = e.x - prev_x                                 dist_y = e.y - prev_y                                          -- Add a physics body that's a flat polygon that follows each segment of the line                                 physics.addBody(lines[line_number], "static", {density = 1, friction = 1, bounce = .1, shape = {0, 0, dist_x, dist_y, 0, 0} } )                                          prev_x = e.x                                 prev_y = e.y                                   line_number = line_number + 1         elseif e.phase == "ended" then                         end                         end         Runtime:addEventListener("touch", runTouch)```

When attempting to combine these two functions, I would substitute(touchme.x,touchme.y) for (e.x,e.y) but since a 'touch event' is no longer present that is not feasible. Multiple attempts at resolving this has proven unsuccessful. What I am attempting is to have what looks like a finger drawing a straight line that some balls will bounce off of. Thanks for help!