2013-12-10 112 views
0

我有一個影片剪輯(startMenu);裏面有按鈕,文字和圖形。這是一款我正在製作的遊戲,它將在Android的不同屏幕尺寸上播放。這是我到目前爲止的代碼:如何讓我的影片剪輯根據屏幕大小調整大小?

stage.scaleMode = StageScaleMode.NO_SCALE; 
stage.align = StageAlign.TOP_LEFT 
startMenu.addEventListener(Event.RESIZE, resizeLayout); 
function resizeLayout(e:Event):void 
{ 
    setPosition(); 
} 
function setPosition():void 
{ 
    startMenu.x = (stage.stageWidth - startMenu.width)/2; 
     startMenu.y = (stage.stageHeight - startMenu.height) /2; 
} 

當我使用調試不同的手機上運行它,它鎖定在左下角,但伸出,以適應整個屏幕。我該怎麼辦?

回答

0

如果您的內容在調整大小和stage.scaleMode = StageScaleMode.NO_SCALE;時延長,那麼您可能在某處修改了剪輯的寬度/高度。

因爲我看不到你的代碼庫,我只能想象它會是這個樣子:

// deforms the image 
myClip.width = stage.fullScreenWidth; 
myClip.height = stage.fullScreenHeight; 

相反,你應該調整隻有一個尺寸,並據此調整了其他百分比,像這樣:

// keeps ratio 
myClip.width = stage.fullScreenWidth; 
myClip.scaleY = myClip.scaleX; 

當然,你不可能總是知道用哪一方來縮放內容,所以你可能想先檢查哪一方更大。例如像這樣:

if (myClip.width > myClip.height) 
{ 
    myClip.width = stage.fullScreenWidth; 
    myClip.scaleY = myClip.scaleX; 
} 
else 
{ 
    myClip.height = stage.fullScreenHeight; 
    myClip.scaleX = myClip.scaleY; 
} 

,然後,像你這樣,對齊夾到容器:

// multiplication works faster, keep that in mind if resizing on each frame or something like this 
// But more importantly - getting width/height is pretty expensive, for frequent resizing pre-calculate and store the width height to avoid recalculation 
startMenu.x = (stage.stageWidth - startMenu.width) * .5; 
startMenu.y = (stage.stageHeight - startMenu.height) * .5; 
相關問題