How to move two objects together with the touch?

Hello Guys,
how can I move two objects together with a single touch drag?

This is the code I used but does not work. (move individually)
Is there a solution?

local lcontre_a_PART1 = display.newImage(“Lcon3_a_PART1.png”)
local lcontre_a_PART2 = display.newImage(“Lcon3_a_PART2.png”)
lcontre_a_PART1.x= 320
lcontre_a_PART2.y= 40
lcontre_a_PART2.x=lcontre_a_PART1.x -40
lcontre_a_PART2.y=lcontre_a_PART2.y +80

physics.addBody( lcontre_a_PART1, “static”, { density=0, friction=0, bounce=0,} )
lcontre_a_PART1.isFixedRotation = true
physics.addBody( lcontre_a_PART2, “static”, { density=0, friction=0, bounce=0,} )
lcontre_a_PART2.isFixedRotation = true

local function moveObject( event )
local t = event.target
local phase = event.phase
if “began” == phase then
t.bodyType = “dynamic”
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
t.isFocus = true

– Store touch position on object
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0

elseif “ended” == phase then
t.bodyType = “static”
display.getCurrentStage():setFocus( nil )
event.target.isFocus = false
end
end
return true
end
lcontre_a_PART1:addEventListener(“touch”,moveObject)
lcontre_a_PART2:addEventListener(“touch”,moveObject)

[import]uid: 25437 topic_id: 15418 reply_id: 315418[/import]

try this
[lua]local lcontre_a_PART1 = display.newCircle(30,30,15)
local lcontre_a_PART2 = display.newCircle(90,90,15)

local function moveObject( event )
local t = event.target
local phase = event.phase
if “began” == phase then
t.bodyType = “dynamic”
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store touch position on object
t.x0 = event.x - lcontre_a_PART1.x
t.y0 = event.y - lcontre_a_PART1.y
t.x1 = event.x - lcontre_a_PART2.x
t.y1 = event.y - lcontre_a_PART2.y
elseif t.isFocus then
if “moved” == phase then
lcontre_a_PART1.x = event.x - t.x0
lcontre_a_PART1.y = event.y - t.y0
lcontre_a_PART2.x = event.x - t.x1
lcontre_a_PART2.y = event.y - t.y1
elseif “ended” == phase then
t.bodyType = “static”
display.getCurrentStage():setFocus( nil )
event.target.isFocus = false
end
end
return true
end
lcontre_a_PART1:addEventListener(“touch”,moveObject)
lcontre_a_PART2:addEventListener(“touch”,moveObject)[/lua] [import]uid: 71210 topic_id: 15418 reply_id: 57011[/import]

thank you very much
… and if I had another pair of objects that move together, but unlike the other? [import]uid: 25437 topic_id: 15418 reply_id: 57037[/import]

write separate function for those 2. [import]uid: 71210 topic_id: 15418 reply_id: 57042[/import]

or else you may try this.
i passed the pair of each object with that object itself.
then u can use the same function for all object pairs.
but this will work if each object have only 1 paired object.

[lua]local lcontre_a_PART1 = display.newCircle(30,30,15)
local lcontre_a_PART2 = display.newCircle(90,90,15)
lcontre_a_PART1.pair = lcontre_a_PART2
lcontre_a_PART2.pair = lcontre_a_PART1

local function moveObject( event )
local t = event.target
local phase = event.phase
if “began” == phase then
t.bodyType = “dynamic”
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store touch position on object
t.x0 = event.x - t.x
t.y0 = event.y - t.y
t.x1 = event.x - t.pair.x
t.y1 = event.y - t.pair.y
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0

t.pair.x = event.x - t.x1
t.pair.y = event.y - t.y1
elseif “ended” == phase then
t.bodyType = “static”
display.getCurrentStage():setFocus( nil )
event.target.isFocus = false
end
end
return true
end
lcontre_a_PART1:addEventListener(“touch”,moveObject)
lcontre_a_PART2:addEventListener(“touch”,moveObject)[/lua] [import]uid: 71210 topic_id: 15418 reply_id: 57044[/import]