Creating a trajectory which changes with touch duration

I need to draw a trajectory along the y axis which increases with touch duration. The longer I touch and hold the screen the higher the object should travel. Please help.

This question is a little nebulous. 

When does the object ‘start’ to move?

Can you elaborate with a ‘for example if I do this, then I should see this’ bullet list of steps?  Be detailed and don’t assume we understand what you mean.

If you mean longuer we press, and more distance is done, so my code will give you a clue.

It move a circle from bottom left to the right and the top.

local w,h=display.contentCenterX,display.contentCenterY local bkg=display.newRect(w,h,2\*w,2\*h) //all the screen bkg.alpha=0.5//put this to 0 local circ=display.newCircle(0,2\*h,30) local t local function f(event)   local p=event.phase      if t and not t.isPause and (p=="ended"or p=="cancelled") then     timer.pause(t)     t.isPause=true   elseif t and t.isPause and (p=="began"or p=="moved") then     timer.resume(t)     t.isPause=false   elseif not t then     function moveCirc()       circ.x,circ.y=circ.x+5,circ.y-10     end           t=timer.performWithDelay(1,moveCirc,0)//the "what to do" function that stop when there is no press   end end bkg:addEventListener("touch",f)

Yvan

roaminggamer

Sorry I wasn’t clear.

I want to modify the code given here.

https://coronalabs.com/blog/2013/04/09/physics-radial-gravity-and-predicting-trajectory/

I want to replace the bolded code.

 

local function fireProj( event )

 

   local proj = display.newImageRect( “object.png”, 64, 64 )

   physics.addBody( proj, { bounce=0.2, density=1.0, radius=14 } )

   proj.x, proj.y = event.xStart, event.yStart

   local vx, vy = event.x-event.xStart, event.y-event.yStart

   proj:setLinearVelocity( vx,vy )

end

The longer I touch and hold the screen higher is the velocity applied to the object. 

yvan

Thanks. I will use your method if I cant figure out how to do it using the formula given in the tutorial.

I modified the original code to do this:

https://www.youtube.com/watch?v=eS4vn91KW0g&feature=youtu.be

Download this and compare the (included) original versus the changed copy:

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/01/PredictingTrajectory.zip

Look for --MOD in main.lua for my changes.

Got it. Thank you so much. I knew I had to use the enterFrame listener but didn’t know how to implement it. Kudos to you for such a detailed and meticulous explanation.

This question is a little nebulous. 

When does the object ‘start’ to move?

Can you elaborate with a ‘for example if I do this, then I should see this’ bullet list of steps?  Be detailed and don’t assume we understand what you mean.

If you mean longuer we press, and more distance is done, so my code will give you a clue.

It move a circle from bottom left to the right and the top.

local w,h=display.contentCenterX,display.contentCenterY local bkg=display.newRect(w,h,2\*w,2\*h) //all the screen bkg.alpha=0.5//put this to 0 local circ=display.newCircle(0,2\*h,30) local t local function f(event)   local p=event.phase      if t and not t.isPause and (p=="ended"or p=="cancelled") then     timer.pause(t)     t.isPause=true   elseif t and t.isPause and (p=="began"or p=="moved") then     timer.resume(t)     t.isPause=false   elseif not t then     function moveCirc()       circ.x,circ.y=circ.x+5,circ.y-10     end           t=timer.performWithDelay(1,moveCirc,0)//the "what to do" function that stop when there is no press   end end bkg:addEventListener("touch",f)

Yvan

roaminggamer

Sorry I wasn’t clear.

I want to modify the code given here.

https://coronalabs.com/blog/2013/04/09/physics-radial-gravity-and-predicting-trajectory/

I want to replace the bolded code.

 

local function fireProj( event )

 

   local proj = display.newImageRect( “object.png”, 64, 64 )

   physics.addBody( proj, { bounce=0.2, density=1.0, radius=14 } )

   proj.x, proj.y = event.xStart, event.yStart

   local vx, vy = event.x-event.xStart, event.y-event.yStart

   proj:setLinearVelocity( vx,vy )

end

The longer I touch and hold the screen higher is the velocity applied to the object. 

yvan

Thanks. I will use your method if I cant figure out how to do it using the formula given in the tutorial.

I modified the original code to do this:

https://www.youtube.com/watch?v=eS4vn91KW0g&feature=youtu.be

Download this and compare the (included) original versus the changed copy:

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/01/PredictingTrajectory.zip

Look for --MOD in main.lua for my changes.

Got it. Thank you so much. I knew I had to use the enterFrame listener but didn’t know how to implement it. Kudos to you for such a detailed and meticulous explanation.