Hello, I am creating some boxes (which I read from the tutorials ) and a dragging event to move them freely on display just to test some stuff. The weird thing that is happening is: When I drag a box on to another one it does not act like it is a physics object it just gets over to other one and overlaps till I remove my finger.
Box spawn code, called with a timer
local boxIndex = {}
local function boxSpawn( event )
boxIndex = boxIndex + 1
boxTable[boxIndex] = display.newImageRect( "box.png", 64, 64 )
local xBox = math.random(0,150)
local yBox = math.random(0,150)
boxTable[boxIndex].x, boxTable[boxIndex].y = xBox, yBox
boxTable[boxIndex]:setReferencePoint(display.TopLeftReferencePoint)
physics.addBody(boxTable[boxIndex], {density = 0.5, friction = 0.3, friction=0.1})
boxTable[boxIndex].id = "Box"..boxIndex
print(boxTable[boxIndex].id)
obj:insert(boxTable[boxIndex])
boxTable[boxIndex]:addEventListener("touch", onTouch)
print("New Box Spawned at:".. xBox ..":"..yBox)
end
And below is the dragging stuff:
local function onTouch( event )
local t = event.target
local phase = event.phase
local stage = display.getCurrentStage()
if "began" == phase then
stage:setFocus(t, event.id)
t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y
if not(t.x0 == 0) and not(t.y0 == 0) then
print("Over")
else
print("Out")
end
elseif t.isFocus then
if "moved" == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
--t.x = event.x - event.x % 32
--t.y = event.y - event.y % 32
print( event.x - t.x0 % 32 .."-".. event.x - t.x0)
elseif "ended" == phase or "cancelled" == phase then
display.getCurrentStage():setFocus( t, nil )
t.isFocus = false
end
end
return true
end
Thanks [import]uid: 73033 topic_id: 24083 reply_id: 324083[/import]