2012-10-17 72 views
4

我試圖切換場景的故事板,但是當我按下按鈕時,它保持當前的場景......我一直無法找到解決這個問題的任何地方互聯網。終端表示它正在打印出「離開主菜單」的方法,並且我的下一個場景已成功打開,但背景和按鈕仍保留在原始場景中。電暈故事板保持以前的場景打開

local storyboard = require("storyboard") 
local widget = require "widget" 
local scene = storyboard.newScene() 

local function onButton(event) 
--local btn = event.target 
--storyboard.gotoScene("sceneTemplate") 
if event.phase == "release" then 
    print("play pressed") 
    storyboard.gotoScene("sceneTemplate") 
    end 
end 

function scene:createScene(event) 
    local group = self.view 

    print("menu scene created") 
end 

function scene:enterScene(event) 
    local group = self.view 

    print("menu scene viewing!") 

    local bgImage = display.newImage("images/mainBG.png",0,0); 

    local playButton = widget.newButton{ 
     default = "images/playUp.png", 
     over = "images/playDown.png", 
     onEvent = onButton 
    } 
    playButton.x = 80 
    playButton.y = 20 
end 

function scene:exitScene(event) 
    local group = self.view 

    print("leaving main menu") 
    storyboard.removeScene("menu") 
    storyboard.removeAll() 
    display.remove(group) 
    group:removeSelf() 
    end 

回答

1

我找到了一個解決方案!如果我同時添加背景圖像和按鈕爲新的顯示組,然後刪除它們時的情景退出,它的作品了:

function scene:enterScene(event) 
    local group = self.view 

    print("menu scene viewing!") 

    local bgImage = display.newImage("images/mainBG.png",0,0); 

    local playButton = widget.newButton{ 
     default = "images/playUp.png", 
     over = "images/playDown.png", 
     onEvent = onButton 
    } 

    displayGroup:insert(bgImage) 
    displayGroup:insert(playButton) 
end 

function scene:exitScene(event) 
    local group = self.view 

    print("leaving main menu") 
    display.remove(displayGroup) 
    storyboard.removeScene("menu") 

end