【问题标题】:(Corona SDK) Scene Transition not playing(Corona SDK)场景转换不播放
【发布时间】:2019-12-19 12:57:56
【问题描述】:

在 Corona SDK 中,我有两个场景。我可以在它们之间加载,但第一个场景不会去渲染,并且过渡 (slideRight) 不会播放。

我尝试在 Scene:Create 和 Scene:Show 部分之间移动场景 1 (Menu.Lua) 的内容,但这并没有做任何事情。我尝试更改过渡和过渡时间,但这并没有改变任何东西,也没有奏效

菜单.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 = "Hours",
            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( "Button Criteria was pressed and released" .. options.effect )
            composer.gotoScene( "scenes.criteria", options )
        end
    end



    -- 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 = "Criteria",
            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  Loading project from:   C:\Users\****\Documents\Corona Projects\Prototype
12:07:34.552  Project sandbox folder: C:\Users\****\AppData\Local\Corona Labs\Corona Simulator\Sandbox\prototype-97576B4B1F269609E1981E30ED94ADC3\Documents
12:07:34.566  Hello World! Main Reporting ##
12:07:35.820  Button Criteria was pressed and releasedslideRight
12:07:35.820  Hello World! Criteria Reporting ##

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

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

    当您在 Composer 中加载新场景时,除非您删除这些场景,否则所有之前的场景仍可访问并保留在内存中。

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

    要将某些内容插入组中,您需要做的就是:

    sceneGroup:insert( buttonhours )
    

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

    【讨论】:

      猜你喜欢
      • 2013-07-20
      • 2016-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多