顯示具有 iOS 標籤的文章。 顯示所有文章
顯示具有 iOS 標籤的文章。 顯示所有文章

2013-07-17

AIR 3.8 for iOS 載入外部 SWF

依據官方說明文件 Loader.load() 「在 iOS 上,您無法載入包含任何 ActionScript ByteCode (ABC) 的 SWF 檔案」,但這是舊版的說明。

AIR 3.6 for iOS 較早版本可以載入 SWC,3.7... 3.8... 為了求真相,以下直接用 AIR 3.8.0.820 for iOS, iPhone 實機,MC Graphics API 做測試。

1) 把 SWF 一同打包到 ipa 裡時 (相同 Application domain),使用文件上的
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
loader.load( new URLRequest('app:/easy_draw.swf'), loaderContext );
SWF 裡的 AS 可以正常執行 (所有東西不用再包成一包 SWF 了, 泣...)

2) 載入 Application domain 以外的 SWF (放在網路上測試),動畫可以正常播放,裡面的 AS 不會 (不能) 執行。

3) 雖然 Application domain 以外的 SWF 裡不能執行 AS,有趣的是載入後 loader.content 是個 MovieClip,而且 MC 的所有屬性都可以用,可以使用 addEventListener() 去偵聽,也可以使用 mc.addFrameScript() 設定 frame actions。而且有命名的子物件,也可以控制。


AIR 到 3.8 (目前還是 beta) 已經可以載入外部的 SWF 並執行,只是因為安全性的問題,依然不讓非 Application domain 的 SWF 執行 AS。希望之後可以開放這個限制,而採用和 AIR for Android 的安全機制,讓我們拭目以待。

Adobe Gaming SDK 1.1 的 SocialUI ANE 有臭蟲

Adobe Gaming SDK 1.1 的 Social.ane 有臭蟲, 根本不能用, 官方論壇也有人問到這個問題, Adobe 終於有人跳出來給了個正常的 ANE.

論壇討論: SocialUI.isSupported always returns false

可正常執行的 Social.ane

SocialUI 提供三種社群的貼文工具: Facebook, Twitter, Weibo。為什麼是這三種? 主要應該是和 iOS 有合作的就這三種,你可以在 iOS 的設定看到她們是一組的。

SocialUI 的功能並不是直接貼文,而是透過 OS 去叫喚社群的 App 來貼文。所以用戶必須安裝那三種社群 Apps,沒裝的話會提醒安裝。Facebook 的貼文也不用建立 FB App 就可以運作,當然這種貼文訊息也就沒有標註 FB App(及其連結)。

2013-06-07

Starling 效能小記

做一個小遊戲的時候遇到生成大地圖的效能問題,用 FarLog 檢視,在 iPad2 各部份花費的時間如下:

0192 ms: 用 Flash MovieClip 拼地圖,未顯示出來,約1200 小片,2000px*2000px。
0031 ms: 建立 BitmapData 物件,尺寸 2000px*2000px,下同。
0094 ms: BitmapData 物件 draw Flash MovieClip。
2974 ms: 由 BitmapData 物件建立 Texture 物件。
0001 ms: 由 Texture 物件建立 Image 物件。

顯然 Texture.fromBitmapData( bitmapData ) 是效能的瓶頸。

後記一: 用 小 Texture 做成 Image 再拼成地圖,建立的全部時間為 356 ms,好很多。But... 執行時地圖要跟著捲動,捲動時效能變得很差。

後記二: Texture.fromBitmapData() 第二個參數 generateMipMaps 設為 false 時,花費時間為原來的 1/10 ~ 1/9,快相當多。MipMaps 有它的好處但大部份時是用不上的。

遠端除錯 FarLog 修正

FarLog 修正,主要是讓訊息可以依照時間排序。舊文章: AIR for iOS 實機測試時的遠端除錯 FarLog
PHP 簡單三個檔: index.php (顯示), log.php (接收) 和 clear.php (清除)。log.php 接收資料記錄到文字檔裡,由 index.php 顯示文字檔內容。
log.php
<?php
if(isset($_REQUEST['log'])) {
  $fp = fopen('log.txt', 'a+');
  fwrite($fp, $_REQUEST['log'] . "\n");
  fclose($fp);
}

index.php
<?php
$filename = 'log.txt';
$fp = @fopen($filename, 'r'); // Open the file

if ($fp) {
  // Add each line to an array
  $array = explode("\n", fread($fp, filesize($filename)));
  // assoc array
  foreach($array as $v) {
    $ar = explode(' : ', $v );
    $assoc_ar[$ar[0]] = $ar[1];
  }

  echo '<meta charset="UTF-8"><pre>';
  ksort($assoc_ar, SORT_NUMERIC); // sort
  foreach($assoc_ar as $k=>$v) {
    echo $k . ' -> ' . $v . "\n";
  }
  echo '</pre>';     
}

clear.php
<?php
unlink('log.txt');

AS 的部份使用 lin.shinder.utils.FarLog 類別的 log() 靜態方法,沒有變更動。

2013-06-06

iOS launch images

iOS launch images: 參考 Adobe 線上說明文件

File name Image size Usage
Default.png 320 x 480 iPhone, standard resolution
Default@2x.png 640 x 960 iPhone, high resolution
Default-568h@2x.png 640 x 1136 iPhone, high resolution, 16:9 aspect ratio
Default-Portrait.png 768 x 1004 (AIR 3.3 and earlier)
768 x 1024 (AIR 3.4 and higher)
iPad, portrait orientation
Default-Portrait@2x.png 1536 x 2008 (AIR 3.3 and earlier)
1536 x 2048 (AIR 3.4 and higher)
iPad, high resolution, portrait orientation
Default-PortraitUpsideDown.png 768 x 1004 (AIR 3.3 and earlier)768 x 1024 (AIR 3.4 and higher) iPad, upside down portrait orientation
Default-PortraitUpsideDown@2x.png 1536 x 2008 (AIR 3.3 and earlier)1536 x 2048 (AIR 3.4 and higher) iPad, high resolution, upside down portrait orientation
Default-Landscape.png 1024 x 768 iPad, left landscape orientation
Default-LandscapeLeft@2x.png 2048 x 1536 iPad, high resolution, left landscape orientation
Default-LandscapeRight.png 1024 x 768 iPad, right landscape orientation
Default-LandscapeRight@2x.png 2048 x 1536 iPad, high resolution, right landscape orientation
Default-example.png 320 x 480 example:// URL on standard iPhone
Default-example@2x.png 640 x 960 example:// URL on high-resolution iPhone
Default-example~ipad.png 768 x 1004 example:// URL on iPad in portrait orientations
Default-example-Landscape.png 1024 x 768 example:// URL on iPad in landscape orientations

2013-05-31

Starling 官方多解析度螢幕的開發指引

Starling 官方多解析度螢幕的開發指引 ", 這篇對於 Starling 寫的 App 同時符合多種解析度裝置, 有詳細的說明。

簡單來說就是利用 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, 放大一倍。

2013-05-27

AIR for iOS 實機測試時的遠端除錯 FarLog

# 2013-06-07 修正:遠端除錯 FarLog 修正

Flash 的 debugging mode 不好用,試了好幾次都沒成功。索性用 Mamp ( Apache, PHP ) 寫了個遠端除錯功能,適合在區域網路內使用。

PHP 簡單三個檔: index.php (顯示), log.php (接收) 和 clear.php (清除)。log.php 接收資料記錄到文字檔裡,由 index.php 顯示文字檔內容。

AIR for iOS 啟始畫面

Default-568h@2x.png 不適合用來當 AIR for iOS 的啟始畫面,因為一閃即逝。

如果是用 Flash CS6 開發的話 (不是用 Flex),可以在主要的 .fla 第一影格放入一個 MovieClip 物件,待 Starling 某些類別載入啟動後再將該 MovieClip 物件除移。

以 Flash/AIR/Starling 測試開發 iOS App for iPhone5 的怪現象

※ 2013-05-31 請看 Starling 官方多解析度螢幕的開發指引, 此篇可以略過了 !!!

或許不是怪現象,可能是最近太少寫 Flash/AS3...

為了在 iPhone 5 可以 640*1136 顯示,放了張啟動用圖 Default-568h@2x.png ( 參考 Deploying AIR Apps on iPhone 5 )。AIR SDK 3.7 和 3.8 beta 情況相同。

AIR for iOS settings,設定:

Aspect Ratio: Landscape (橫向)
  勾選 Full screen
  勾選 Auto orientation
Resolution: High

stage (場景) 設定不同時就有怪怪的情況:

stage: 1136*640, FPS:60 -> 一開始執行就卡住
stage: 1136*640, FPS:30 -> 開始幾個畫面位置大跑位,後面的畫面卻正常
stage: 568*320, FPS:30 -> 正常


明明就已經 Full screen 了啊, 花熱發... Orz

2013-05-27 更新 ------------------------------------
應該在判斷是 iOS 後, 使用 Capabilities.screenResolutionX 和 screenResolutionY。

在 document class 放 stage 的 resize 偵聽器發現 ( resolution 設為 high ),一開始 stage 的大小會被調整為原來 stage 大小的兩倍,之後 ( 約 1~ 2 sec ) 會被調整成 screen 大小。這就可以解釋之前的現象了。

FB 留言