Hi All.
I have tried to implement some camera tracking and touch to move camere, but I keep running in to a problem…
It seems my very simple drag and drop code Begins to misbehave if i move the displayGroup where the obejct i want to drag is placed.
For example I have this tracking code:
function track(self,event) local target = self if target ~= nil then local targetx = 100 - target.x local targety = 100 - target.y screenGroup.x = screenGroup.x + ((targetx - screenGroup.x)\*0.1) --screenGroup.y = screenGroup.y + ((targety - screenGroup.y)\*0.1) end end
I put it on the object I want to drag, but as soon as I do this I become unable to move the object in the Y direction.
I also tried another example where I just move the displayGroup to the left very simply by screenGroup.x = screenGroup.x - 10
This also result in this behaviour…
I drag and drop with this code
function dragAndDrop( event ) -- A general function for dragging physics bodies local body = event.target local phase = event.phase local stage = display.getCurrentStage() if "began" == phase then stage:setFocus( body, event.id ) body.isFocus = true -- Create a temporary touch joint and store it in the object for later reference body.tempJoint = physics.newJoint( "touch", body, event.x, event.y ) elseif body.isFocus then if "moved" == phase then -- Update the joint to track the touch body.tempJoint:setTarget( event.x, event.y ) elseif "ended" == phase or "cancelled" == phase then stage:setFocus( body, nil ) body.isFocus = false -- Remove the joint when the touch ends body.tempJoint:removeSelf() end end -- Stop further propagation of touch event return true end
When I view the app in debug mode it seems the line between my mouse pointer and the object i move is flying around the screen, and the object does the same …
Any ideas … Is it something like I need to put the joint into the screengroup somehow…