类型 字符串 事件 show 修订版 2024.3703 版 关键字 composer、scene、show、event
对于 show 事件,如果场景即将变为活动状态,event.phase
为 "will"
的 字符串 值;如果场景出现在屏幕上,则为 "did"
。可从对分派到 [scene][api.type.scene] 对象的 show 事件的事件侦听器访问它。如果指定了场景转换效果,则在场景效果开始执行前分派 "will"
阶段。与此相反,在效果结束后才分派 "did"
阶段。
-------------------------- -- 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" )