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]