How to detect two touches?

I want to move the display object which is touched first to posititon which is touched next.Can u suggest me the code to do this?

If you look in the provided sample code (your Corona SDK install directory)/SampleCode/Interface there are several multi-touch app examples. That might be a great place to start.

Rob

I dont want multitouch.I want to move the display object which i want to touch first so that i can recognize which object to move and touch another place where i want to move it.

I would use a variable, perhaps named “objectTouched”.  In the touch handler on the object that’s first touched, you could do something like:

if event.phase == "began" then      objectTouched = event.target end

in your touch handler.

Then you can have a touch handler on the background or in a zone where you want allow moves to, and when you detect that spot has been tapped, perhaps use a transition.to() to move the object to the spot:

if event.phase == "began" then     transition.to( objectTouched, { time = 500, x = event.x, y = event.y } ) end

What do u mean by having touch handler in background?

Since I have no clue what your game consists of, I’m making a few assumptions.  Almost every game has a background image that they load (even if its a solid rectangle).  You either have some separate image that shows the user where they can move things too, or your background would contain the art that shows the user where things can move to.  Either way, you have a display object and if your art is part of the background, you can add a touch handler to that:

local objectTouched local function placeObject( event )      if event.phase == "began" then          if objectTouched and objectTouched.removeSelf then -- test to make sure objectTouched is a display object              transition.to( objectTouched, { time = 500, x = event.x, y = event.y } )          end      end end -- further down the code.... local background = display.newImageRect("someimage.png", someWidth, someHeight) -- depending on how your app is setup background:addEventListener( "touch", placeObject ) 

or something like that!

Rob

Thank you

If you look in the provided sample code (your Corona SDK install directory)/SampleCode/Interface there are several multi-touch app examples. That might be a great place to start.

Rob

I dont want multitouch.I want to move the display object which i want to touch first so that i can recognize which object to move and touch another place where i want to move it.

I would use a variable, perhaps named “objectTouched”.  In the touch handler on the object that’s first touched, you could do something like:

if event.phase == "began" then      objectTouched = event.target end

in your touch handler.

Then you can have a touch handler on the background or in a zone where you want allow moves to, and when you detect that spot has been tapped, perhaps use a transition.to() to move the object to the spot:

if event.phase == "began" then     transition.to( objectTouched, { time = 500, x = event.x, y = event.y } ) end

What do u mean by having touch handler in background?

Since I have no clue what your game consists of, I’m making a few assumptions.  Almost every game has a background image that they load (even if its a solid rectangle).  You either have some separate image that shows the user where they can move things too, or your background would contain the art that shows the user where things can move to.  Either way, you have a display object and if your art is part of the background, you can add a touch handler to that:

local objectTouched local function placeObject( event )      if event.phase == "began" then          if objectTouched and objectTouched.removeSelf then -- test to make sure objectTouched is a display object              transition.to( objectTouched, { time = 500, x = event.x, y = event.y } )          end      end end -- further down the code.... local background = display.newImageRect("someimage.png", someWidth, someHeight) -- depending on how your app is setup background:addEventListener( "touch", placeObject ) 

or something like that!

Rob

Thank you