Hello I have a basic drag function that I got from the website and modified a little bit for my needs.
What I want to learn is how can I modify it in a way that when I start to drag objects they fall/hang/rotate whatever you say around the point I touch the body.
local function onTouch( event )
local t = event.target
--print ("onTouch - event: " .. tostring(event.target), event.phase, event.target.x, tostring(event.id) )
-- Print info about the event. For actual production code, you should
-- not call this function because it wastes CPU resources.
local phase = event.phase
if "began" == phase then
-- Make target the top-most object
local parent = t.parent
print ( parent )
parent:insert( t )
display.getCurrentStage():setFocus( t, event.id )
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
-- t.x = event.x / 32
-- t.y = event.y / 32
t.x = (event.x - t.x0) / 32
t.y = (event.y - t.y0) / 32
elseif "ended" == phase or "cancelled" == phase then
if not(nil == t.id) then
t:removeSelf()
else
display.getCurrentStage():setFocus( t, nil )
t.isFocus = false
end
end
end
return true
end
[import]uid: 73033 topic_id: 23743 reply_id: 323743[/import]