You’re almost doing it already.
I don’t know what the other object is called, so I refer to it as ‘secondObject’. Put your variable name in. The changes I’ve made are (not counting comments) only 3 lines…
[lua]local function rotateObj(event)
local t = event.target
local phase = event.phase
if (phase == “began”) then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position of finger
t.x1 = event.x
t.y1 = event.y
– store initial rotation of t
t.startRotation = t.rotation
elseif t.isFocus then
if (phase == “moved”) then
t.x2 = event.x
t.y2 = event.y
angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
print("angle1 = "…angle1)
rotationAmt = angle1 - angle2
–rotate it
t.rotation = t.rotation - rotationAmt
print ("t.rotation = "…t.rotation)
t.x1 = t.x2
t.y1 = t.y2
– HERE SHOULD GO THE CODE TO MOVE THE OBJECTB BUT I DON’T KNOW WHAT TO PUT HERE
– get difference between initial rotation and current rotation
local diffRot = t.rotation - t.startRotation
– set second object’s vertical position
secondObject.y = secondObject.y + diffRot
elseif (phase == “ended”) then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
– Stop further propagation of touch event
return true
end
yourObject:addEventListener(“touch”, rotateObj)[/lua]
[import]uid: 8271 topic_id: 16223 reply_id: 60925[/import]