Total Pageviews

Thursday, April 17, 2014

composer.showOverlay()

composer.showOverlay()
សំរាប់ហ្វាំងសិនមួយនេះប្រើសំរាប់ loads an overlay scene នៅពីលើ currently active scene (the parent scene) ដែលធ្វើឪ្យ parent scene intact។ នៅពេល overlay ត្រូវបានបង្ហាញ, an overlay specific scene event paramenter, event.parent នឹងត្រូវ dispatched ទៅកាន់ overlay scene។ សំរាប់ parameter ផ្តល់ជាមួយនឹង reference ទៅកាន់ parent scene object ដូចនេះអាចហៅវា ហ្វាំងសិន។ សូមមើល composer.hideOverlay() សំរាប់ការប្រើកូដ។ ហ្វាំងសិននេះវា supports គ្រប់ទាំង scene transition effects ទាំងអស់ដែលមាននៅលើ composer.gotoScene()
ដើម្បីការពារ touches on the overlay scene ពីការ passing through to underying objects ដូចជា button & widgets ត្រូវបញ្ចូល isModal option to true

ចំនាំះ
 មានតែ one overlay scene ត្រូវបង្ហាញក្នុងពេលតែម្តង។ បើសិនជាហៅ composer.gotoScene(), composer.removeHidden() ឬព្យាយាមក្នុងការបង្ហាញនៅ overlay ផ្សេង ពេលនោះ current scene នឹងត្រូវលាក់។ ដូចនេះត្រូវលាក់ overlay scene មុនពេល
១. ក្នុងការចង់បង្ហាញនៅ overlay ផ្សេង
២.​ ផ្លាស់ប្តូរនៅ active scene តាមរយះ composer.gotoScene()

Syntax: composer.showOverlay (sceneName [, options])
sceneName(តំរូវការ) វាជា String ដែលជាឈ្មោះរបស់ scene ដែលត្រូវ load ជា overlay
options(ជំរើស) វាជាតារាងដែលផ្ទុកនៅ several transition related options ដូចជា effect type, custom parameters

Overlay options:
សំរាប់ Options table វាផ្ទុកនៅ various position
local options =
{
    isModal = true,
    effect = "fade",
    time = 400,
    params = {
        sampleVar1 = "my sample variable",
        sampleVar2 = "another sample variable"
    }
}
isModal(ជំរើស) វាជា Boolean វាត្រូវបានបញ្ចូលទៅកាន់ true, វានឹងការពារនៅ touches passing through the overlay scene ទៅកាន់ objects នៅក្នុង underlying scene។ default is false
effect(ជំរើស) វាជា string ដែលទាក់ទងនឹង overlay transition
time(ជំរើស) វាជាចំនួនលេខដែលជាពេលវេលារបស់ ​​effect, default is 500 miliseconds
params(ជំរើស) វាជាតារាង ដែលជា table containing any kind of custom data ដែលត្រូវ transferred ទៅកាន់ overlay។ នៅក្នុង overlay ទិន្នន័យត្រូវបាន accessed តាមរយះ event.params នៅក្នុង create event or show event

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

local scene = composer.newScene()

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


No comments:

Post a Comment