Hey guys,
I am using the simple “drag” sample code that comes with corona. I have a display group that is draggable, and scalable. Inside of this display group are several individual objects that are dragable using the simple “drag” code.
My problem is that when the display group that holds these individual objects is scaled up or down, then when I try to drag one of the individual objects contained inside of the display group, the object being dragged does not stay under my finger.
All I can think is to multiply the dragged object’s new x/y values by the objects scale, but that doesn’t work. There has to be a simple solution to this, any ideas?
Here is what I am doing:
--Changing groups scale manually just for testing on PC floorPlanGroup.xScale = 0.75 floorPlanGroup.yScale = 0.75 --Dragged already placed markers fRef.dragMarker = function ( event ) local t = event.target local phase = event.phase if "began" == phase then -- Make target the top-most object local parent = t.parent parent:insert( t ) display.getCurrentStage():setFocus( t ) -- Spurious events can be sent to the target, e.g. the user presses -- elsewhere on the screen and then moves the finger over the target. -- To prevent this, we add this flag. Only when it's true will "move" -- events be sent to the target. t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y elseif t.isFocus then if "moved" == phase then -- Make object move (we subtract t.x0,t.y0 so that moves are -- relative to initial grab point, rather than object "snapping"). --I thought that I could multiply here by the dragged group's x and y scale values t.x = (event.x - t.x0) \* floorPlanGroup.xScale t.y = (event.y - t.y0) \* floorPlanGroup.yScale elseif "ended" == phase or "cancelled" == phase then --If marker object isn't part of the floorPlanGroup then insert it if t.parent.name ~= "floorPlanGroup" then t.x, t.y = t.x - floorPlanGroup.x, t.y - floorPlanGroup.y floorPlanGroup:insert(t) end display.getCurrentStage():setFocus( nil ) t.isFocus = false --Record placement data into JSON client file for i=1, #markerTable, 1 do decodedClientFile["floorPlanPlacements"][i] = { type = markerTable[i].id, x = markerTable[i].x, y = markerTable[i].y } end --Save update to the client file fRef.saveCurrentClient(global.currentClientName) end end -- Important to return true. This tells the system that the event -- should not be propagated to listeners of any objects underneath. return true end
Thanks in advance!
