过渡场景不起作用

时间:2014-07-18 11:52:59

标签: ios lua corona

我是lua的新手。我正在使用corona sdk和outlook来编辑代码。我正在创建一个简单的游戏,但面临一个奇怪的问题。我的屏幕是这样的:

  

主菜单 - >游戏玩法 - >结束游戏画面

在结束屏幕中,玩家可以选择再次播放或通过进入主菜单屏幕来改变难度。当我使用composer.gotoScene( "play", "fade", 500 )时,它可以正常工作,但是当我使用composer.gotoScene( "main_menu", "fade", 500 )时,它不会做任何事情。有谁知道为什么?

这是我的代码:

local composer = require( "composer" )
local scene = composer.newScene()
-- include Corona's "widget" library
local widget = require "widget"

-- local forward references should go here
local playBtn;
local exitBtn;

-- -------------------------------------------------------------------------------

local function onPlayBtnRelease()
    composer.gotoScene( "play", "fade", 500 )
    return true -- indicates successful touch
end

local function onExitBtnRelease()
    composer.gotoScene( "main_menu", "fade", 500 )
    return true -- indicates successful touch
end


-- "scene:create()"
function scene:create( event )

    local sceneGroup = self.view
    -- Initialize the scene here.
    -- Example: add display objects to "sceneGroup", add touch listeners, etc.'

    playBtn = widget.newButton{
        label="",
        defaultFile="playbutton_up1.png",
        overFile="playbutton_up1.png",
        width=206, height=65,
        onRelease = onPlayBtnRelease    -- event listener function
    }
    playBtn.x = display.contentWidth * 0.25
    playBtn.y = display.contentHeight * 0.35


    exitBtn = widget.newButton{
        label = "",
        defaultFile="exitbutton_up.png",
        overFile="exitbutton_up.png",
        width=206, height=65,
        onRelease = onExitBtnRelease    -- event listener function
    }
    exitBtn.x = display.contentWidth*0.75
    exitBtn.y = display.contentHeight/1.05

end


-- "scene:show()"
function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Called when the scene is still off screen (but is about to come on screen).
    elseif ( phase == "did" ) then
        -- Called when the scene is now on screen.
        -- Insert code here to make the scene come alive.
        -- Example: start timers, begin animation, play audio, etc.
    end
end


-- "scene:hide()"
function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Called when the scene is on screen (but is about to go off screen).
        -- Insert code here to "pause" the scene.
        -- Example: stop timers, stop animation, stop audio, etc.
    elseif ( phase == "did" ) then
        -- Called immediately after scene goes off screen.
    end
end


-- "scene:destroy()"
function scene:destroy( event )

    local sceneGroup = self.view

    -- Called prior to the removal of scene's view ("sceneGroup").
    -- Insert code here to clean up the scene.
    -- Example: remove display objects, save state, etc.
end


-- -------------------------------------------------------------------------------

-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

-- -------------------------------------------------------------------------------

return scene

1 个答案:

答案 0 :(得分:1)

您需要将元素插入到场景视图中。

sceneGroup:insert( playBtn )