【问题标题】:Corona going to previous scene results in black screen电晕转到上一个场景导致黑屏
【发布时间】:2013-05-04 08:51:05
【问题描述】:

我遇到了这个问题,它使我的游戏延迟了一个里程碑,在场景 1 中,我单击了将我带到菜单的菜单按钮,然后当用户想要再次播放时,他们单击播放按钮,他们应该转到以前的场景,但是当它发生时,它会进入黑屏。这是一些代码,这是场景 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 )

【问题讨论】:

  • 有人有想法吗?我找不到其他有同样问题的人。
  • 在没有看到场景创建代码的情况下,很难弄清楚为什么会得到一个空白场景。虽然我也很好奇你为什么要调用 previousScene?你现在不知道你需要从你的菜单中去哪个场景吗?您是否打印出 previousScene 的值以确保它是您所期望的?
  • 我正在调用上一个场景,因为我希望它将用户带到他们离开的最后一个场景。它是一个单词查找游戏,我正在尝试通过如何进入菜单来实现 4 pics 1 word 的概念,然后当你想再次玩时,你只需点击播放,它就会带你到你所在的最后一个级别.
  • 检查我在第一篇文章底部所做的编辑。
  • 好吧,完整的代码在电晕实验室的一个线程中,暂时没有人最终回复:forums.coronalabs.com/topic/…

标签: lua storyboard coronasdk


【解决方案1】:

尝试使用点击侦听器而不是触摸侦听器。我没有看到你的整个代码,但我认为有问题。

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

【讨论】:

  • 不,那没有用,请检查我的第一篇文章,因为我在底部进行了编辑。
  • 我编辑了答案。您的问题出在 exitScene() 函数中。你不应该调用 destroyScene() 函数。查看新代码。
  • 我试过你的代码,但它仍然给我一个黑屏,我想知道这是一个错误还是代码真的有问题,因为它只发生在我从 800 更新时发生到最新的公开版本,似乎很少有人有解决方案:(。它让我的游戏回到了一个里程碑!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多