Total Pageviews

Monday, March 17, 2014

Display.contentScaleX Vs display.contentScaleY

វាជា Ratio ដែលនៅចន្លោះ Content Pixel & Screen Pixel width។ តំលៃរបស់វាតែងតែ ១ អ្នកអាចកែប្រែបានតាមរយះ config.lua ដែលបញ្ជាក់អំពី content’s height & width។ វាមាន Mood ផ្សេងៗទៀតដូចជា “letterbox” “zoomEven” ដែលជាលទ្ធផលនៃ Scale ដែលខុសគ្នា។
សូមមើលកូដះ
Config.lua
application =
{
    content =
    {
        width = 320,
        height = 480,
        scale = "letterbox"
    },
}    
Main.lua
local scalex = display.contentScaleX
local scaley = display.contentScaleY

-- display scale values
print( "scaleX", scalex )
print( "scaleY", scaley )

-- OUTPUT:
-- iPhone 4
-- scaleX 0.5
-- scaleY 0.5

-- iPad 1/2
-- scaleX 0.46875
-- scaleY 0.46875
ចង់ដឹងអំពី ប្រវែង Width & Height គិតជា pixel ដូចនេះការប្រើ display ពិតជាអាចជួយបាន។ មើលការប្រើប្រាស់ Print statement ដូចនេះ
Print (display.pixelWidth .. display.pixelHeight)
ការប្រើ (..concat) សំរាប់ភ្ជាប់ Print statement ទាំងពីរនេះ។ មានន័យថា អ្នកអាចដឹងអំពី Smart Devices របស់អ្នកមានប៉ុន្មាន pixel?
Display.screenOriginX / Y តើវាមានប្រយោជន៏អ្វីខ្លះ? វានឹងត្រឡប់មកនៅ x distance ពីខាងឆ្វេង មកដល់ content area។ ដូចជានៅក្នុង “letterbox” & “zoomEven” របស់ Mood៕ វាប្រើសំរាប់បន្ថែម ឬក៏ កាត់ចេញពី Current Device។ អត្ថប្រយោជន៏មួយទៀតគឺ អោយរកឃើញ Visible area ដែលត្រូវ បន្ថែម ឬ លុបចេញពី Current device។
សូមមើលកូដះ
-- Create a grey background
local background = display.newRect( 0, 0, 320, 480 )
background:setFillColor( 0.5 )

-- Create two squares
local rect1 = display.newRect( 0, 0, 50, 50 )
local rect2 = display.newRect( 0, 0, 50, 50 )

-- Place the squares along the top edge
-- Offset the second square with display.screenOriginX
rect1.x = 25
rect2.x = 25 + display.screenOriginX  
rect1.y = 25
rect2.y = 150

No comments:

Post a Comment