2012-09-14 94 views
0

我想設置我的mc到iPhone上使用空氣as3的確切屏幕大小。as3空氣的ios獲取屏幕設備分辨率

我已經厭倦了:

import flash.display.Screen; 
import flash.geom.Rectangle; 

var mainScreen:Screen = Screen.mainScreen; 
var screenBounds:Rectangle = mainScreen.bounds; 

/// Does not work - comes out 320 by 480 
w.text = ""+screenBounds.width+""; 
h.text = ""+screenBounds.height+""; 
BG.height = screenBounds.height; 
BG.width = screenBounds.width; 

/// Does not work - comes out 320 by 480 
w.text = ""+Capabilities.screenResolutionX+""; 
h.text = ""+Capabilities.screenResolutionY+""; 
BG.height = Capabilities.screenResolutionY; 
BG.width = Capabilities.screenResolutionX; 

/// Does not work - comes out 320 by 480 
w.text = ""+stage.fullScreenwidth+""; 
h.text = ""+stage.fullScreenHeight+""; 
BG.height = stage.fullScreenHeight; 
BG.width = stage.fullScreenWidth; 


/// Works BUT... it does NOT stretch to fit the stage. 
/// I am starting with android screen size and it shrinks it proportionally 
/// which means there is space on top or bottom or left side. 
w.text = ""+stage.stageWidth+""; 
h.text = ""+stage.stageHeight+""; 
BG.height = stage.stageHeight; 
BG.width= stage.stageWidth; 

回答

1

您可以嘗試玩弄在Stage.scaleMode:

stage.scaleMode = StageScaleMode.SHOW_ALL; 

stage.scaleMode = StageScaleMode.EXACT_FIT; 
+0

EXACT_FIT的作品,但我的MC被壓扁。 :( 是否有一個allowScale? –

+0

如果應用的縱橫比與設備的縱橫比不匹配,那麼您幾乎沒有選擇。您必須使用letterbox(顯示左邊的黑條),將它縮小(打破縱橫比)或剪輯一些內容 –

+0

我想如果我只能得到正確的寬度和高度的屏幕,然後我可以只改變背景,但是這是行不通的 –

1

如果出來和小320x480你說這是錯誤的,我可以假設你正在使用iPhone 4S?如果是這樣,請進入App Descriptor XML文件。往底部(通常是文件中最後一項),應該有這條​​線。

<requestedDisplayResolution>standard</requestedDisplayResolution> 

如果它被註釋掉或設置爲「標準」,這將是你的問題。改變它說「高」,這將啓用視網膜支持。 「標準」將非視網膜顯示(iPhone上的320x480,iPad上的1024x768)縮放到上。 「高」會給你正確的顯示分辨率。

+0

謝謝,我把它改爲「高」,但它似乎仍然不適合。 –

1

,如果別人是有越來越適用於iOS的屏幕分辨率的問題。發生的情況是,在完成加載的swf和調用屏幕大小的時間之間沒有足夠的時間。

對於我的應用程序,我需要swf沒有比例,因爲我通過以百分比爲屏幕大小設置相對值來設置我所有的剪​​輯大小和位置。

如果我的舞臺是800x1280,並且我有一個高度= 100,寬度= 100的剪輯;

然後是相同的說,我的clips.height = int(stage.stageWidth * 0.125); as 100 * 100/800 = 12.5; | 100是800的12.5%;

訣竅是,你的第一幀(如果你使用閃光燈)

只是搭建了舞臺的規模和等待滿載的SWF,和這一點。

stage.align = StageAlign.TOP_LEFT; 
stage.scaleMode = StageScaleMode.NO_SCALE; 

var loadTimer:Timer = new Timer(10); 
    loadTimer.addEventListener(TimerEvent.TIMER, loading); 
    loadTimer.start(); 

function loading(evt){ 
    if(root.loaderInfo.bytesLoaded == root.loaderInfo.bytesTotal){ 
     loadTimer.stop(); 
     loadTimer.removeEventListener(TimerEvent.TIMER, loading); 
     gotoAndPlay(2); 
     } 
    } 

然後在框架2,你可以調用stage.stageWidth,它會給你真正的大小,因爲你必須給予足夠的時間,應用程式該值。

var stageW:int = stage.stageWidth; 
var stageH:int = stage.stageHeight; 

我希望它能幫助,感謝