event.phase

Type String
Event show
Revision Release 2022.3683
Keywords composer, scene, show, event

Overview

For the show event, event.phase is the string value of "will" if the scene is about to become active, or "did" after the scene comes on screen. It can be accessed from the event listener for show events that are dispatched to [scene][api.type.scene] objects. If a scene transition effect is specified, the "will" phase is dispatched before the scene effect begins execution. In contrast, the "did" phase is not dispatched until after the effect is finished.

Example

--------------------------
-- From "scene1.lua"
--------------------------
composer.gotoScene( "scene2", { effect="fade", time=800 } )

--------------------------
-- In "scene2.lua"
--------------------------
local composer = require( "composer" )
local scene = composer.newScene()

function scene:show( event )

    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:addEventListener( "show" )