Hi guys, I did a similar test like ChRu here
http://developer.anscamobile.com/forum/2010/10/31/swap-depth-order
It is a basic test, where I have 3 dragable objects, that can overlap each other.
I made the group:insert() work on a touch event, so the touched object is always in the foreground.
The problem that I have is that when the 3 objects are on top of each other, it seems that always the bottom one gets picked. Instead I want to have the top one to be picked. As far as I understood, the touch event always is supposed to pick the top object (as described here http://developer.anscamobile.com/content/application-programming-guide-event-handling).
here is the code of my a test:
object01 = display.newRect(100,100,50,50)
object01 :setFillColor(255,0,0)
object02 = display.newRect(60,100,50,50)
object02 :setFillColor(0,255,0)
object03 = display.newRect(60,100,50,50)
object03 :setFillColor(0,0,255)
group1 = display.newGroup()
group1:insert(object01)
group1:insert(object02)
group1:insert(object03)
eventoffset = {x=0,y=0}
---------------- drag function
local function dragging (event)
local stage = display.getCurrentStage()
local target = event.target
if event.phase == "began" then -- on touch
stage:setFocus(target, event.id)
eventoffset.x = event.x - target.x
eventoffset.y = event.y - target.y
group1:insert(target)
end
if event.phase == "moved" then -- on move
target.x = event.x - eventoffset.x
target.y = event.y - eventoffset.y
end
if event.phase == "ended" or event.phase == "cancelled" then -- on release
stage:setFocus(nil)
end
end
------------------
object01:addEventListener("touch", dragging)
object02:addEventListener("touch", dragging)
object03:addEventListener("touch", dragging)
Am I doing somethng wrong ? [import]uid: 10177 topic_id: 3269 reply_id: 303269[/import]
[import]uid: 10177 topic_id: 3269 reply_id: 10095[/import]
[import]uid: 10820 topic_id: 3269 reply_id: 10115[/import]