简体   繁体   中英

(Corona SDK) Scene Transition not playing

In Corona SDK, I Have two Scenes. i am able to load between them, but the 1st Scene doesn't de-render, and the transition (slideRight) Doesn't play.

I Tried Moving Scene 1 (Menu.Lua)'s Content between the Scene:Create & Scene:Show parts, however this didn't do anything. i tried changing the transition & the transition time, but this didn't change anything, and it didn't work

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 = "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

Here's my Console, as you can see the button is pressed and we go to the 2nd scene, however the 1st scene is still loaded and there is no transition


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 ##

If you use Composer, Corona's official built-in scene, then you should read through the guide: https://docs.coronalabs.com/guide/system/composer/index.html

When you load a new scene in composer, all of the previous scenes remain accessible and in memory unless you remove the scenes.

In your case, the reason why the display objects don't move is because you haven't inserted them into the sceneGroup. If you want Corona to handle your display objects automatically, then you must insert the display objects either into display groups and then insert these display groups into the sceneGroup, or insert the display objects directly to the sceneGroup.

In order to insert something into a group, all you need to do is:

sceneGroup:insert( buttonhours )

Another mistake that you are running into is that you have two local variables named "buttonhours". When you create the second variable, then you lose the reference to the original one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM