Total Pageviews

Thursday, April 17, 2014

Total properties របស់ composer library()


composer.isDebug
នេះជា toggles “composer debug mode” ដែលបើសិនជាវាត្រូវបានបញ្ចូល true, ពេលនោះវានឹង prints នៅ useful debugging information ទៅកាន់ Corona Terminal។ វាត្រូវបញ្ចូលជា false (default) មុនពេលចាប់ផ្តើម building project for deployment
Syntax: composer.isDebug
សូមមើលកូដះ
Composer.isDebug = true

composer.recycleOnLowMemory
បើសិនជា OS issues a low memory warning, composer នឹងចាប់ផ្តើម automatically recycle the scene ដោយប្រើ least recently (that scene’s self.view នឹងត្រូវលុបចេញ) បើសិនជាចង់ដាក់ជា disable auto-recycling ត្រូវដាក់ property ទៅជា false, default is true
Syntax: composer.recycleOnLowMemory

សូមមើលកូដះ
-- Turn off auto-recycle on low memory (recommended only for advanced situations)
composer.recycleOnLowMemory = false  

composer.recycleOnSceneChange
by default, នៅពេលចាប់ផ្តើមផ្លាស់ប្តូរ scenes, composer នឹងថែរក្សានៅ current scene’s view នៅក្នុង memory ដែលវាអាចជូយក្នុងការបង្ហាញបើសិនជា access នៅ scene ដូចគ្នា។ បើសិនជាចង់ recycle the current scene នៅពេលប្តូរទៅកាន់ new scene (remove the current scene’s self.view) បញ្ចូលវាជា composer.recycleOnSceneChange ទៅជា true ដែលតំលៃដើមវាជា false
syntax: composer.recycleOnSceneChange

សូមមើលកូដះ
-- Enable auto-recycle on scene change
composer.recycleOnSceneChange = true


composer.stage
វាប្រើសំរាប់ត្រឡប់ជា reference ទៅកាន់ top level composer display group ដែលគ្រប់ scene views ទាំងអស់ត្រូវបានបញ្ចូល។ វាអាចជា composer scene layer ហើយមានប្រយោជន៏បើសិនជាត្រូវការ place display objects នៅពីលើឬពីក្រោម all composer scenes, ទោះបីជានៅក្នុង transition effect:
ឧទាហរណ៏ះ
•A background image that is displayed behind all Composer scenes and remains static, even during scene transitions.
 •A tab or UI bar that appears above all Composer scenes.
 •HUD (heads-up display) elements such as health, score, etc.


Syntax:  composer.stage

សូមមើលកូដះ
 local composer = require( "composer" )
--Create a background which should appear behind all scenes
local background = display.newImage( "bg.png" )
-- Create a "health meter" image which should appear above all scenes
local meter = display.newImage( "health100.png" )
meter.anchorX = 0
meter.anchorY = 1
meter.x, meter.y = 20, display.contentHeight-20
-- Sort everything in the correct z-index order
local stage = display.getCurrentStage()
stage:insert( background )
stage:insert( composer.stage )
stage:insert( meter )
-- Open the initial scene
composer.gotoScene( "scene1", "fade", 800 )
                                       
នេះគឺជា Scene template:
វាអាចប្រើក្នុងការបង្កើត new scene files។ វាមានទាំង listener functions សំរាប់គ្រប់ទាំង potential events នៅក្នុង Scene, ប៉ុន្តែគ្រាន់តែរួមបញ្ចូលនៅ Listeners សំរាប់ Events ដែលចង់ Handles

local composer = require( "composer" )
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called.
-- -----------------------------------------------------------------------------------------------------------------
-- local forward references should go here
-- -------------------------------------------------------------------------------
-- "scene:create()"
function scene:create( event )
    local sceneGroup = self.view
    -- Initialize the scene here.
    -- Example: add display objects to "sceneGroup", add touch listeners, etc.
end
-- "scene:show()"
function scene:show( event )
    local sceneGroup = self.view
    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:hide()"
function scene:hide( event )
    local sceneGroup = self.view
    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, stop audio, etc.
    elseif ( phase == "did" ) then
        -- Called immediately after scene goes off screen.
    end
end
-- "scene:destroy()"
function scene:destroy( event )
    local sceneGroup = self.view
    -- Called prior to the removal of scene's view ("sceneGroup").
    -- Insert code here to clean up the scene.
    -- Example: remove display objects, save state, etc.
end
-- -------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -------------------------------------------------------------------------------

return scene

No comments:

Post a Comment