【问题标题】:Transition scene not working过渡场景不起作用
【发布时间】:2014-07-18 22:04:38
【问题描述】:

我是 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

【问题讨论】:

    标签: ios lua coronasdk


    【解决方案1】:

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

    sceneGroup:insert( playBtn )
    

    等等

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 2017-03-27
      相关资源
      最近更新 更多