I have tried to create a grid logic for your requirement. now I may need to know the shapes your objects will be of. then we need to map the grid columns which are occupied. and privent movement of object to occupied column.
this is what I reached so far…
[lua]local rect1,rect2,rect3
local function moveObject( 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 )
t.isFocus = true
elseif t.isFocus then
if “moved” == phase then
local gridx = math.floor(event.x/50)
local gridy = math.floor(event.y/50)
local gridxpos = gridx * 50
local gridypos = gridy * 50
if gridx > -1 and gridx < 5 and gridy > -1 and gridy < 9 then
t.x = gridxpos
t.y = gridypos
end
elseif “ended” == phase then
display.getCurrentStage():setFocus( nil )
event.target.isFocus = false
end
end
return true
end
local line1,line2
local x = 50
for i=1,10 do
line1 = display.newLine(0,x,320,x)
line2 = display.newLine(x,0,x,480)
line1.alpha = .2
line2.alpha = .2
x=x+50
end
rect1 = display.newRect(0,0,100,50)
rect1:setReferencePoint(display.TopLeftReferencePoint)
rect1:addEventListener(“touch”,moveObject)
rect2 = display.newRect(150,150,100,50)
rect2:setReferencePoint(display.TopLeftReferencePoint)
rect2:addEventListener(“touch”,moveObject)
rect3 = display.newRect(200,200,100,50)
rect3:setReferencePoint(display.TopLeftReferencePoint)
rect3:addEventListener(“touch”,moveObject)[/lua] [import]uid: 71210 topic_id: 15218 reply_id: 56682[/import]