1

我遇到了这个问题,它使我的游戏延迟了一个里程碑,在场景 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 )
4

1 回答 1

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 )
于 2013-05-05T20:48:10.593 回答