how to set bring to front and bring to back with an object

hi,

if I would display an my object in front of the background but i want to keep the order of the variable 's declaration.

How to ?

local object =... local background=... function() --in a partular case object is bring to front compared to background end

thanks in advance

[lua]

object:toFront()

[/lua]

Have you heard of google? :wink:

Ho sorry :frowning: it’s clear that is a stupid question. the next time i search a little more…

thanks for your response

object:toFront() is not working in composer scene

I just tested it and it works as expected.  Perhaps post some code showing what you’re doing?  You can’t toFront a composer scene object of another object that is unmanaged/not inserted into the scene group.

Rob

I created a function (listener) which runs on pressing button (widget). The function moves the object:toFront(). Here is the code

--------------------------- start of scene create

local DecoImg
local function handlerButton(event)
If(“ended”==event.phase) then
— here create new display.newImage at same position as DecoImg but not added to sceneGroup and newImage is still visible above decoImg
DecoImg:toFront() --not working
end
end

local button1 = widget.newButton
{
width = 100, height = 50,
defaultFile = “button-norm.png”,
overFile = “button-push.png”,
label = “button”,
onEvent = handlerButton
}
button1.x = display.contentCenterX
button1.y = 50
sceneGroup:insert(button1)

DecoImg = display.newImage…
sceneGroup:insert(DecoImg)

------------------------ end of Scene create

You cannot move something in a scene’s group in front of something that’s not in the scene’s group.  By design any display object **NOT** in the Corona sceneGroup will always be on top.

In this case, toFront only moves DecoImg to the top most layer in sceneGroup…

Rob

[lua]

object:toFront()

[/lua]

Have you heard of google? :wink:

Ho sorry :frowning: it’s clear that is a stupid question. the next time i search a little more…

thanks for your response

object:toFront() is not working in composer scene

I just tested it and it works as expected.  Perhaps post some code showing what you’re doing?  You can’t toFront a composer scene object of another object that is unmanaged/not inserted into the scene group.

Rob

I created a function (listener) which runs on pressing button (widget). The function moves the object:toFront(). Here is the code

--------------------------- start of scene create

local DecoImg
local function handlerButton(event)
If(“ended”==event.phase) then
— here create new display.newImage at same position as DecoImg but not added to sceneGroup and newImage is still visible above decoImg
DecoImg:toFront() --not working
end
end

local button1 = widget.newButton
{
width = 100, height = 50,
defaultFile = “button-norm.png”,
overFile = “button-push.png”,
label = “button”,
onEvent = handlerButton
}
button1.x = display.contentCenterX
button1.y = 50
sceneGroup:insert(button1)

DecoImg = display.newImage…
sceneGroup:insert(DecoImg)

------------------------ end of Scene create

You cannot move something in a scene’s group in front of something that’s not in the scene’s group.  By design any display object **NOT** in the Corona sceneGroup will always be on top.

In this case, toFront only moves DecoImg to the top most layer in sceneGroup…

Rob