Corona转到上一个场景导致黑屏

时间:2013-05-04 08:51:05

标签: lua storyboard corona

我遇到的问题是延迟我的游戏一个里程碑,在scene1中我单击菜单按钮将我带到菜单然后当用户想要再次播放时他们点击播放按钮他们应该去之前的场景然而当它进入黑屏时。这是一些代码,这是场景1中的主菜单按钮:

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 )

1 个答案:

答案 0 :(得分: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

<强> -------------------------------------------- ----------------
新代码:
-------------------------------------------------- ----------
在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 )