将 sceneGroup 插入场景后,如何将其置于后台?

很抱歉,我不知道如何在标题中描述这个问题。

local bBbackground = display.newRoundedRect( Backgroundrectangle.x+(Backgroundrectangle.width/4), Backgroundrectangle.y, 100, 125, 10 )
sceneGroup:insert(bBbackground)
bBbackground.id = "b"
bBbackground.strokeWidth = 2
bBbackground:setFillColor( gradient )
bBbackground:setStrokeColor( 0.2 )

bBmenutext = display.newText( "Bb", 100, 200, "Comic Sans MS", 50)
bBmenutext.x = bBbackground.x
bBmenutext.y = bBbackground.y - aAbackground.height/6
bBmenutext:setFillColor( 0.2 )
bBscoretext = display.newText( "4/8", 100, 200, "Comic Sans MS", 30)
bBscoretext.x = bBbackground.x
bBscoretext.y = bBbackground.y + bBbackground.height/4
bBscoretext:setFillColor( 0.7 )
sceneGroup:insert(bBmenutext)
sceneGroup:insert(bBscoretext)

如果我将 sceneGroup:insert 去掉,那么一切都会如我所愿:bBmenutext 和 bBscoretext 将出现在 bBbackground 的前面。但是,现在的情况是,这些文本分组在 bBbackground 的后面。我还尝试了添加以下代码:

bBbackground:toBack()
bBmenutext:toFront()
bBscoretext:toFront()

但是都没有起到作用。请问有什么解决方案吗?我对 Corona 还比较陌生,而最大的挫折就是要确保在场景结束时删除所有内容。我真的需要想办法把这些元素放入到那个组中,但是又不会完全搞砸。

谢谢。

点赞
用户7026995
用户7026995

我使用了你的代码 场景模板 进行了检查,它能够如预期地工作。

test.lua

local composer = require( "composer" )

local scene = composer.newScene()

-- -----------------------------------------------------------------------------------
-- 场景事件函数下方的代码只会被执行一次,除非场景通过 "composer.removeScene()" 被完全移除(而不是回收)。
-- -----------------------------------------------------------------------------------

-- -----------------------------------------------------------------------------------
-- 场景事件函数
-- -----------------------------------------------------------------------------------

-- scene:create()
function scene:create( event )

    local sceneGroup = self.view

    local bBbackground = display.newRoundedRect( display.contentCenterX, display.contentCenterY, 100, 125, 10 )
    sceneGroup:insert(bBbackground)
    bBbackground.id = "b"
    bBbackground.strokeWidth = 2
    bBbackground:setFillColor( gradient )
    bBbackground:setStrokeColor( 0.2 )

    local bBmenutext = display.newText( "Bb", 100, 200, "Comic Sans MS", 50)
    bBmenutext.x = bBbackground.x
    bBmenutext.y = bBbackground.y - 30
    bBmenutext:setFillColor( 0.2 )

    local bBscoretext = display.newText( "4/8", 100, 200, "Comic Sans MS", 30)
    bBscoretext.x = bBbackground.x
    bBscoretext.y = bBbackground.y + bBbackground.height/4
    bBscoretext:setFillColor( 0.7 )

    sceneGroup:insert(bBmenutext)
    sceneGroup:insert(bBscoretext)

end

-- scene:show()
function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- 当场景还未完全呈现在屏幕上时调用此处代码(场景切换动画开始之前)

    elseif ( phase == "did" ) then
        -- 当场景完全呈现在屏幕上时调用此处代码

        physics.start()
    end
end

-- scene:hide()
function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- 当场景即将从屏幕上卸载时调用此处代码(场景切换动画即将开始)

    elseif ( phase == "did" ) then
        -- 当场景完全从屏幕上卸载之后调用此处代码

    end
end

-- scene:destroy()
function scene:destroy( event )

    local sceneGroup = self.view
    -- 此处代码在场景的视图被移除之前运行。

end

-- -----------------------------------------------------------------------------------
-- 将画面事件函数添加到场景事件监听器
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------

return scene

main.lua

local composer = require( "composer" )

composer.gotoScene( 'test' )
2017-04-18 11:18:03