Hi,
I’m creating 2 displaygroups, 1 with a background, then another with a button.
When displayed, the button(group) is always displayed UNDER the background group, even when i load the backgroundgroup first.
I tried bgGroup:toBack() without result.
Funny thing is, when i want to drag the background around, and use t:toBack() in the startDrag function (line 36), the background group is set back properly, and the button is now on top of the background.
What am i doing wrong?
[code]
module(…, package.seeall)
new = function ( params )
– Display Objects
bgGroup = display.newGroup()
background = display.newImage(“images/common/locations/background.jpg”, 0,0 )
bgGroup:insert( background )
mainGroup = display.newGroup()
button = display.newImage(“images/common/btnBack.png”, 0,0 )
button.x = 64
button.y = 716
mainGroup:insert( button )
bgGroup:toBack()
local function startDrag(event )
local t = event.target
local phase = event.phase
if “began” == phase then
Dragging = false
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
– t:toBack()
elseif t.isFocus then
if “moved” == phase then
Dragging = true
t.x = event.x - t.x0
t.y = event.y - t.y0
if t.x > 0 then
t.x = 0
end
if t.x < -1024 then
t.x = -1024
end
if t.y < -768 then
–t.y = -768
end
if t.y > 0 then
t.y = 0
end
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
– Stop further propagation of touch event!
return true
end
local initVars = function ()
– Inserts
bgGroup:addEventListener( “touch”, startDrag )
bgGroup:toBack()
end
– Initiate variables
initVars()
– MUST return a display.newGroup()
return mainGroup
end
[/code] [import]uid: 50459 topic_id: 25634 reply_id: 325634[/import]
