2013-10-16 187 views
0

我有AIR本機擴展存在問題。 對於我的學士論文,我必須在平板電腦上創建多人遊戲,其中玩家通過藍牙進行通信。 我必須使用AIR來實現我的遊戲,因爲它必須適用於所有平板電腦(IPad,Samsung Tablets,...) 我必須使用AIR本機擴展,因爲ActionScript沒有藍牙API。Adob​​e AIR本機擴展

我有一個關於我的話題一些問題:

  1. 這是真的,我要實現我的C擴展本機代碼?我讀過Java本地代碼只適用於Android。

  2. 對於本地擴展,我需要本地代碼,充當接口的ActionScript庫,這些都可以清除。但是我不知道爲什麼我需要一個Flex項目來創建AIR Native Extension?我只是想從我的遊戲中調用本地方法。我希望任何人都可以向我解釋。

謝謝你幫助我。

回答

2
  1. 您需要爲每個平臺編寫本地代碼。所以你需要用Java(Android)和Objective-C(iOS)編寫代碼。擴展只不過是本地代碼的橋樑
  2. 您不需要Flex來使用本機擴展。原生擴展應完全用ActionScript編寫,擴展的本機部分使用本地語言編寫(Java,Objective-C或C++,具體取決於平臺)

您應該查看Adobe的資源提供的主題。 ANE並不是世界上記錄最多的功能,但有很多資源可以幫助您入門。另外,已經有公開的ANE允許藍牙支持。我從來沒有測試過它們,所以我不能保證它們的有效性,但如果你可以使用第三方庫,那麼可能值得給它們看看。

http://www.adobe.com/devnet/air/native-extensions-for-air.html http://help.adobe.com/en_US/air/extensions/air_extensions.pdf http://help.adobe.com/en_US/air/build/WS597e5dadb9cc1e0253f7d2fc1311b491071-8000.html http://www.adobe.com/devnet/air/articles/ane-android-devices.html http://www.adobe.com/devnet/air/articles/building-ane-ios-android-pt1.html

+0

您可以使用第三方庫,但您必須使用鏈接攻擊/解決方法才能讓它們在ANE中正確鏈接。 – Nabren

+0

@Nabren重讀說什麼。我從來沒有說過在擴展中使用第三方庫。我只是問,提問者是否可以在他的學校項目中使用它們。如果可以的話,他應該使用已經建好的ANE,這樣他就不必經歷自己建造自己的麻煩了。 –

+0

哦,我很抱歉。我認爲這個說法是:「我從來沒有測試過它們,所以我不能保證它們的有效性,但如果你可以使用第三方庫,可能值得給它們看看。」意味着在ANE中使用第三方庫,我只是想澄清。再次,我的道歉。 – Nabren

0

有由我們寫的教程,MyFlashLab團隊,可能對你有用,這裏的鏈接http://www.myflashlabs.com/build-multiplayer-games-in-adobe-air-using-bluetooth-ane/,這裏是初始化和添加偵聽到的一些關鍵點藍牙ANE。

var _ex:Bluetooth = new Bluetooth(); 

// dispatches the state of Bluetooth whenever it changes (you will know if it's on or off) 
_ex.addEventListener(BluetoothEvent.BLUETOOTH_STATE , bluetoothState); 

// dispatches the communication state of two devices 
_ex.addEventListener(BluetoothEvent.COMMUNICATION_STATUS , communication); 

// dispatches the connection state of two devices. Are the devices connected or not. 
_ex.addEventListener(BluetoothEvent.CONNECTION , connection); 

// dispatches the 'enable' and 'visibility' dialog states 
_ex.addEventListener(BluetoothEvent.DIALOG_STATUS , dialog); 

// dispatches the device discovering state 
_ex.addEventListener(BluetoothEvent.DISCOVERING_STATUS , discovering); 

// dispatches when new devices are discovered 
_ex.addEventListener(BluetoothEvent.NEW_DISCOVERD , newDiscoverd); 

// dispatches whenever a new String message is received from the other device 
_ex.addEventListener(BluetoothEvent.READ_MESSAGE , readMessage); 

// dispatches to notify you about the scan mode of the device 
_ex.addEventListener(BluetoothEvent.SCAN_MODE , scanMode); 

// dispatches when a String message is sent to the other device 
_ex.addEventListener(BluetoothEvent.SEND_MESSAGE , sendMessage); 

// check if Bluetooth hardware is on or off 
if (_ex.isEnable) 
{ 
    // make Bluetooth visible to others infinitely 
    // or set a duration which must be between 0 and 3600 
    _ex.visible(0); 

    // start the communication service for Bluetooth 
    _ex.initCommunicationService(); 
} 
else 
{ 
    // if it's not on, just turn it on 
    _ex.enable(); 
} 

// listen to know when the Bluetooth is turning on 
function bluetoothState(e:BluetoothEvent):void 
{ 
    trace("state >> " + e.param); 

    if (e.param == "bluetoothOn") 
    { 
     // as soon as it's on, make it visible and start the communication service 
     _ex.visible(0); 
     _ex.initCommunicationService(); 
    } 
}