Need To Combine 2 Functions

My game requires the user to draw lines with their fingers.  In the instructions I want an image of a finger drawing the line.

This is the finger moving function:

[lua]

 

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})

    --transition=easing.inOutQuad 

    

    

end

touchMove() 

 

 

 

The function that allows the user to draw a line with there finger is as follows:

[lua]

 

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)

 

 

 

 

So I want to combine these  2 functions so it appears the finger in transition is drawing the line.  Any help will be much appreciated!

Hi @russm305,

So to be clear, you want a sort of instructional demonstration showing a “fingerprint” (or whatever) moving in a directional transition, and as it transitions, you want a line to draw behind it? And if so, this instructional portion is “separate” from the touch drawing method, except that you want it to mimic what will happen when the user actually does this action on the screen?

 

I also might note, this code appears to be applying a vast amount of physics bodies (one per “move” which could be an object that is just a few pixels in size). While not technically illegal, this is a huge number of physics objects to plot along a line. You might want to control how many physics bodies get created by either:

 

  1. creating a body between two line points only when the distance is over a certain threshold.

  2. creating bodies separated by a certain distance, with the assumption that if some other object is going to collide with this “line” or a ball roll along it, from a physics standpoint, you might not need bodies so tightly-packed along the line to sense collision (meaning, you should create just enough bodies so that an object can’t pass between two points, and an object rolling along it doesn’t appear to be on a “bumpy road”).

 

Brent

So to be clear, you want a sort of instructional demonstration showing a “fingerprint” (or whatever) moving in a directional transition, and as it transitions, you want a line to draw behind it?

 

–Yes that is exactly what I am looking for!!!  Please help!!!  The line must have the physics so balls will roll along.  Would it be possible if you could provide in code format also thanks!

 

I also might note, this code appears to be applying a vast amount of physics bodies (one per “move” which could be an object that is just a few pixels in size). While not technically illegal, this is a huge number of physics objects to plot along a line.

 

–  It was the only function that I could find that would allow me to draw a line quickly and not have objects fall through. It works great with no lag or anything.  To be honest I’m not entirely sure how it works so if I tried doing what you are saying it wouldn’t work out so well :frowning:

Hi @russm305,

So to be clear, you want a sort of instructional demonstration showing a “fingerprint” (or whatever) moving in a directional transition, and as it transitions, you want a line to draw behind it? And if so, this instructional portion is “separate” from the touch drawing method, except that you want it to mimic what will happen when the user actually does this action on the screen?

 

I also might note, this code appears to be applying a vast amount of physics bodies (one per “move” which could be an object that is just a few pixels in size). While not technically illegal, this is a huge number of physics objects to plot along a line. You might want to control how many physics bodies get created by either:

 

  1. creating a body between two line points only when the distance is over a certain threshold.

  2. creating bodies separated by a certain distance, with the assumption that if some other object is going to collide with this “line” or a ball roll along it, from a physics standpoint, you might not need bodies so tightly-packed along the line to sense collision (meaning, you should create just enough bodies so that an object can’t pass between two points, and an object rolling along it doesn’t appear to be on a “bumpy road”).

 

Brent

So to be clear, you want a sort of instructional demonstration showing a “fingerprint” (or whatever) moving in a directional transition, and as it transitions, you want a line to draw behind it?

 

–Yes that is exactly what I am looking for!!!  Please help!!!  The line must have the physics so balls will roll along.  Would it be possible if you could provide in code format also thanks!

 

I also might note, this code appears to be applying a vast amount of physics bodies (one per “move” which could be an object that is just a few pixels in size). While not technically illegal, this is a huge number of physics objects to plot along a line.

 

–  It was the only function that I could find that would allow me to draw a line quickly and not have objects fall through. It works great with no lag or anything.  To be honest I’m not entirely sure how it works so if I tried doing what you are saying it wouldn’t work out so well :frowning: