2013-05-04 49 views
1

我有這個問題,是由scene1中的一個里程碑延遲我的遊戲,我點擊菜單按鈕,帶我到菜單,然後當用戶想再次玩,他們點擊播放按鈕,然後當它進入黑屏時,它們應該轉到上一個場景。這裏是一些代碼,這是在場景1中的主菜單按鈕:Corona去前場景導致黑屏

function scene:enterScene(event) 

local group = self.view 

function menubutton:touch(event) 
if event.phase == "began" then 
    storyboard.gotoScene("menu", "slideRight", 750) 
    audio.play(click) 
    display.getCurrentStage():setFocus(event.target) 
    event.target.isFocus = true 
elseif event.target.isFocus then 
    if event.phase == "moved" then 
     print("user has moved their finger off the button.") 
    elseif event.phase == "ended" then 
     print("user has switched to the main menu") 
     display.getCurrentStage():setFocus(nil) 
     event.target.isFocus = false 
    end 
end 
return true 

這裏是主菜單上的播放按鈕:

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

local function onSceneTouch(event) 
    if event.phase == "ended" then 
     audio.play(click) 
     local previousScene = storyboard.getPrevious() 
     if previousScene == nil then 
     storyboard.gotoScene("scene1", "slideLeft", 750) else 
     storyboard.gotoScene(previousScene) 
     return true 
    end 
end 
end 

什麼想法?我在模擬器輸出中沒有出現錯誤。

編輯:這行代碼停止了空白屏幕,當我把它放在菜單上,但只有圖像顯示,背景圖像按鈕圖像等,但沒有別的。

local prior_scene = storyboard.getPrevious() 
storyboard.purgeScene(prior_scene) 
+0

沒有人有一個想法?我找不到其他人有同樣的問題。 – 2013-05-05 01:18:39

+0

如果沒有看到你的場景創建代碼,你將很難弄清楚爲什麼你會得到一個空白的場景。雖然我也很好奇你爲什麼要調用previousScene?你不知道現在你需要從你的菜單中選擇什麼樣的場景嗎?你打印出previousScene的價值,以確保它是你所期望的嗎? – 2013-05-05 20:12:16

+0

我打電話給前一個場景,因爲我想讓用戶走到他們離開的最後一個場景。它是一個字找到遊戲,我試圖做4個圖片1個字的概念,你如何去菜單,然後當你想再玩一次,你只需點擊玩,它會把你帶到你最後一級。 – 2013-05-06 05:49:04

回答

0

嘗試使用輕敲偵聽器而不是觸摸偵聽器。我沒有看到你的整個代碼,但我認爲存在這個問題。場景1

主菜單按鈕:在主菜單現場

function scene:enterScene(event) 

    local group = self.view 

    local function onMenuButtonTap(event) 
     audio.play(click) 
     storyboard.gotoScene("menu", "slideRight", 750) 
     return true 
    end 
end 

播放按鈕:

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

    local function onPlayTap(event) 
     audio.play(click) 
     local previousScene = storyboard.getPrevious() 
     if previousScene == nil then 
      storyboard.gotoScene("scene1", "slideLeft", 750) 
     else 
      storyboard.gotoScene(previousScene) 
     end 
     return true 
    end 
end 

---------------- --------------------------------------------
新代碼:
------------------------------------------------- -----------

change th在你scene1.lua

function scene:exitScene(event) 

    local group = self.view 
    storyboard.destroyScene("scene1") 

end 

與此

function scene:exitScene(event) 

    local group = self.view 

end 

在你menu.lua補充一點:

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

    storyboard.purgeScene("scene1") 
end 

scene:addEventListener("createScene", scene) 
+0

沒有,沒有工作,請檢查我的第一篇文章,因爲我放下了底部的編輯。 – 2013-05-06 05:53:31

+0

我編輯了答案。你的問題在** exitScene()**函數中。你不應該調用** destroyScene()**函數。查看新代碼。 – vovahost 2013-05-08 17:31:16

+0

我試過了你的代碼,但它仍然給我一個黑屏,我想知道這是一個錯誤還是代碼有問題,因爲它只發生在我從800更新到最新的公開發布時發生,非常很少有人似乎有一個解決方案:(其設置我的遊戲回到了一個里程碑! – 2013-05-09 07:05:15