event.phase

类型 字符串
事件 隐藏
修订 版本 2024.3703
关键词 composer,场景,隐藏,事件

概述

对于 hide 事件,当场景在屏幕上(但即将离开屏幕)时,event.phase字符串 值为 "will"。相反,在场景离开屏幕后,event.phase字符串 值将立即变为 "did"。如果为新场景或覆盖图指定了场景过渡效果,则在效果开始执行之前调度 "will" 阶段,并在效果完成后调度 "did" 阶段。

示例

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

function scene:hide( event )

    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, unload audio, etc.
    elseif ( phase == "did" ) then
        -- Called immediately after scene goes off screen.
    end
end
scene:addEventListener( "hide" )