2017-04-18 17 views
0

我不知道如何在標題中描述這個問題,抱歉。在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:插入那麼一切就是我想要的:bBmenutext和bBscoretext出現在bBbackground的前面。然而,實際情況是,文本組落後於它。我也嘗試加入:

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

但無濟於事。請任何解決方案?我對科羅娜頗爲陌生,實際上最大的挫折一直試圖確保在場景結束時一切都被消除。我真的需要弄清楚如何讓事情進入該羣體而不會完全搞砸。

謝謝。

回答

1

我把你的代碼是scene template來檢查。它將按預期

test.lua

local composer = require("composer") 

local scene = composer.newScene() 


-- ----------------------------------------------------------------------------------- 
-- Code outside of the scene event functions below will only be executed ONCE unless 
-- the scene is removed entirely (not recycled) via "composer.removeScene()" 
-- ----------------------------------------------------------------------------------- 




    -- ----------------------------------------------------------------------------------- 
    -- Scene event functions 
    -- ----------------------------------------------------------------------------------- 

    -- 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) 

     bBmenutext = display.newText("Bb", 100, 200, "Comic Sans MS", 50) 
     bBmenutext.x = bBbackground.x 
     bBmenutext.y = bBbackground.y - 30 
     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) 

    end 


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

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

     if (phase == "will") then 
      -- Code here runs when the scene is still off screen (but is about to come on screen) 

     elseif (phase == "did") then 
      -- Code here runs when the scene is entirely on screen 
    physics.start() 
     end 
    end 


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

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

     if (phase == "will") then 
      -- Code here runs when the scene is on screen (but is about to go off screen) 

     elseif (phase == "did") then 
      -- Code here runs immediately after the scene goes entirely off screen 

     end 
    end 


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

     local sceneGroup = self.view 
     -- Code here runs prior to the removal of scene's view 

    end 


    -- ----------------------------------------------------------------------------------- 
    -- Scene event function listeners 
    -- ----------------------------------------------------------------------------------- 
    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') 
+0

問題解決了。謝謝。 bBbackground已經在一個組中,因此將它從前面的組中刪除並修復它。 – Atrag