簡單來說就是利用 viewPort 的尺寸和 starling.stage.stageWidth, starling.stage.stageHeight 大小來調整內容的縮放比 ( starling.contentScaleFactor )。
例如:
if (CheckingOS.osIsIOS) {
Starling.multitouchEnabled = true;
sy = Capabilities.screenResolutionX; // Landscape
sx = Capabilities.screenResolutionY; // Landscape
} else {
sx = this.stage.stageWidth;
sy = this.stage.stageHeight;
}
Starling.handleLostContext = true;
switch(sx) {
case 480: // iPhone 3GS: 320 * 480
use_iPad_strategy = false;
viewPort = new Rectangle(0, 0, 480, 320);
_starling = new Starling(Main, stage, viewPort);
sx = _starling.stage.stageWidth = 960;
sy = _starling.stage.stageHeight = 640;
break;
case 960: // iPhone 4S: 640 * 960
case 1136: // iPhone 5: 640 * 1136
use_iPad_strategy = false;
viewPort = new Rectangle(0, 0, sx, sy);
_starling = new Starling(Main, stage, viewPort);
_starling.stage.stageWidth = sx;
_starling.stage.stageHeight = sy;
break;
case 1024: // iPad 2: 768 * 1024
use_iPad_strategy = true;
viewPort = new Rectangle(0, 0, sx, sy);
_starling = new Starling(Main, stage, viewPort);
_starling.stage.stageWidth = sx;
_starling.stage.stageHeight = sy;
break;
case 2048: // iPad 3: 1536 * 2048
use_iPad_strategy = true;
viewPort = new Rectangle(0, 0, sx, sy);
_starling = new Starling(Main, stage, viewPort);
sx = _starling.stage.stageWidth = 1024;
sy = _starling.stage.stageHeight = 768;
break;
}
上面的程式, iPhone 3GS 的 contentScaleFactor 為 0.5, 縮小為原來一半。iPhone 4、4S、5 和 iPad2 的 contentScaleFactor 為 1。New iPad 的 contentScaleFactor 為 2, 放大一倍。