Total Pageviews

Thursday, April 17, 2014

composer.hideOverlay()


composer.hideOverlay()
នេះជាហ្វាំងសិនដែលប្រើសំរាប់ លាក់ឬលុប ចំពោះ current overlay scene, បើសិនជាមាន scene មួយត្រូវបានបង្ហាញ។ នៅពេលដែលវា overlay is hidden, ពេលនោះ overlay-specific scene event parameter, event.parent នឹងត្រូវ dispatched ទៅកាន់ overlay scene។ សំរាប់ parameter ផ្តល់នៅ reference ទៅកាន់ parent scene object ដូចនេះអាចហៅហ្វាំងសិនជាមួយនឹងវា
Syntax: composer.hideOverlay ( [ recycleOnly] [, effect] [, time] )
recycleOnly(ជំរើស) វាជា Boolean បើសិនជាបញ្ចូលទៅកាន់ true, scene នឹងត្រូវ recycled (the self.view) ដែលជា display group ត្រូវបានលុបចេញ, ប៉ុន្តែវានៅក្នុង memory។ ការបញ្ចូលនេះទៅកាន់ true គឺមាន ប្រយោជន៏ណាស់បើសិនជាចង់បង្ហាញនៅ overlay again នៅពេលខាងមុខ។ តំលៃដើមគឺ false មានន័យថា overlay scene ត្រូវបានលុបចេញរួមទាំង its scene object
effect(ជំរើស) វាជា String ដែល visual transition effect ដែលមានលើ overlay before it is hidden។ គ្រប់បញ្ចីរបស់ transition effect ដែលមាននៅក្នុង composer.gotoScene()
time(ជំរើស)វាជាចំនួនលេខដែលជាពេលវេលារបស់ ​effect។ តំលៃដើមគឺ ៥០០​milliseconds

សូមមើលកូដះ
------------------------------------------------------------------------------
-- In "scene1.lua" (parent scene)
------------------------------------------------------------------------------
local composer = require( "composer" )

local scene = composer.newScene()

-- Custom function for resuming the game (from pause state)
function scene:resumeGame()
    --code to resume game
end

-- Options table for the overlay scene "pause.lua"
local options = {
    isModal = true,
    effect = "fade",
    time = 400,
    params = {
        sampleVar = "my sample variable"
    }
}

-- By some method (a pause button, for example), show the overlay
composer.showOverlay( "pause", options )

return scene

------------------------------------------------------------------------------
-- In "pause.lua"
------------------------------------------------------------------------------
local composer = require( "composer" )

local scene = composer.newScene()

function scene:hide( event )
    local sceneGroup = self.view
    local phase = event.phase
    local parent = event.parent  --reference to the parent scene object

    if ( phase == "will" ) then
        -- Call the "resumeGame()" function in the parent scene
        parent:resumeGame()
    end
end

-- By some method (a "resume" button, for example), hide the overlay
composer.hideOverlay( "fade", 400 )

scene:addEventListener( "hide", scene )
return scene


No comments:

Post a Comment