(Corona SDK) 场景过渡未播放

在 Corona SDK 中,我有两个场景。我能够在它们之间切换,但第一个场景没有被卸载, 过渡(slideRight)没有播放。

我尝试将 Scene 1(Menu.Lua)的内容移到 Scene:Create 和 Scene:Show 部分之间,但是这没有产生任何效果。我尝试更改过渡和过渡时间,但这没有改变任何东西,也没有起作用。

Menu.Lua

local composer = require( "composer" )
local widget = require( "widget" )
local scene = composer.newScene()

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

    local sceneGroup = self.view
    -- Code here runs when the scene is first created but has not yet appeared on screen

    -- Setup
    function setup (x)
      print ("Hello World! Main Reporting ##")
      display.setDefault("background", 0.2, 0.2, 0.2)
      local startimage = display.newImage ( x )
      startimage.x = display.contentCenterX
      startimage.y = display.contentCenterY
    end

    setup("ugh.jpeg")
    -- Button

    local options =
    {
        effect = "slideRight",
        time = 400

    }

    -- Create the widget
    local buttonhours = widget.newButton(
        {
            shape = "roundedrect",
            fillColor = { default={ 0.2, 0.2, 0.2, 0.7 }, over={ 1, 0.2, 0.5, 1 } },
            x = display.contentCenterX - 75,
            y = display.contentCenterY,
            width = 125,
            height = 45,
            id = "button1",
            label = "工作时间",
            font = "Courier New",
            fontSize = 25,
            labelColor = { default={ 1, 1, 0.95 }, over={ 0, 0, 0, 0.5 } },
            onEvent = handleButtonhoursEvent
        }
    )

    local function handleButtonCriteriaEvent( event )

        if ( "ended" == event.phase ) then
            print( "按钮 Criteria 被按下并释放" .. options.effect )
            composer.gotoScene( "scenes.criteria", options )
        end
    end

    -- Create the widget
    local buttoncriteria = widget.newButton(
        {
            shape = "roundedrect",
            fillColor = { default={ 0.2, 0.2, 0.2, 0.7 }, over={ 1, 0.2, 0.5, 1 } },
            x = display.contentCenterX + 75,
            y = display.contentCenterY,
            width = 125,
            height = 45,
            id = "button2",
            label = "准则",
            font = "Courier New",
            fontSize = 25,
            labelColor = { default={ 1, 1, 0.95 }, over={ 0, 0, 0, 0.5 } },
            onEvent = handleButtonCriteriaEvent
        }
    )
end

Criteria.Lua

local composer = require( "composer" )

  local scene = composer.newScene()

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

      local sceneGroup = self.view
      -- Code here runs when the scene is first created but has not yet appeared on screen
      display.setDefault("background", 0.2, 0.2, 0.2)
      print ("Hello World! Criteria Reporting ##")
  end

下面是我的控制台,正如您看到的,按钮被按下,我们进入了第二个场景,但第一个场景仍然加载,并且没有过渡效果


12:07:34.552  从加载项目:C:\Users\****\Documents\Corona Projects\Prototype
12:07:34.552  项目沙盒文件夹:C:\Users\****\AppData\Local\Corona Labs\Corona Simulator\Sandbox\prototype-97576B4B1F269609E1981E30ED94ADC3\Documents
12:07:34.566  Hello World! Main Reporting ##
12:07:35.820  按钮 Criteria 被按下并释放slideRight
12:07:35.820  Hello World! Criteria Reporting ##
点赞
用户88888888
用户88888888

如果你使用 Composer(Corona的官方内置场景),那么你应该阅读指南:https://docs.coronalabs.com/guide/system/composer/index.html

当你在Composer中加载一个新场景时,除非你将场景移除,否则所有先前的场景仍然保持可访问和存在于内存中。

在你的情况下,显示对象不移动的原因是因为你没有将它们插入到场景组中。如果你希望Corona自动处理你的显示对象,那么你必须将显示对象插入到显示组中,然后将这些显示组插入到场景组中,或者直接将显示对象插入到场景组中。

为了将某物插入到一个组中,你只需这样做:

sceneGroup:insert( buttonhours )

你遇到的另一个错误是你有两个名为“buttonhours”的局部变量。当你创建第二个变量时,你就失去了对原始变量的引用。

2019-08-18 00:31:55