0

我正在开发 AS3/AIR for mobile(Android 和 iOS)中的多人游戏,我想在游戏中实现本地多人游戏(在同一个 wifi 网络/蓝牙上)功能。这样做的最佳选择是什么?

  • 如果它是跨平台的就好了(android <-> iOS)
  • 如果我在本地多人游戏中使用点对点和 Adob​​e Cirrus 服务 (RTMFP),我会遇到任何问题吗,因为该项目处于测试阶段?
  • 我已经知道这篇文章:http: //forum.starling-framework.org/topic/google-play-game-services-ane-1#post-74449
  • 我也浏览过这篇文章:http ://www.as3gamegears.com/category/multiplayer/但我喜欢的一些选项使用 RTMFP,我对此表示怀疑!所以请建议我是否可以使用??
  • 我可以使用 AIR sdk 提供的 Datagram Sockets 类吗??虽然我不确定,但 RTMFP 和 TCP/数据报套接字之间是否有任何连接?

如果我需要更多详细信息,我可以指定!!!

谢谢

4

3 回答 3

0

我使用 Adob​​e Cirrus,它运行良好。我使用了可用的文档,开始两台设备之间的通信大约需要 30 分钟。在我看来,这是最好的选择。

于 2015-01-23T12:37:27.523 回答
0

您可以尝试在 AIR for iOS(和 OSX)中使用低功耗蓝牙。此处演示:http ://www.youtube.com/watch?v=tiRfYjq4wh0&index=1&list=PLw76-mHQ5mhdmHPJy05n424-DKde1XM8G 。ANE 库在这里:http://flashpress.ru/blog/ane/bluetooth/? lang=en

中央管理器:


package 
{
    import flash.display.Sprite;

    import ru.flashpress.ane.queue.FPQueueData;
    import ru.flashpress.ane.queue.FPQueueTypes;
    import ru.flashpress.bluetooth.FPBluetooth;
    import ru.flashpress.bluetooth.constants.FPbtState;
    import ru.flashpress.bluetooth.data.FPBluetoothOptions;
    import ru.flashpress.bluetooth.events.FPBluetoothEvent;
    import ru.flashpress.bluetooth.events.FPCentralManagerEvent;
    import ru.flashpress.bluetooth.events.FPCharacteristicEvent;
    import ru.flashpress.bluetooth.events.FPPeripheralEvent;
    import ru.flashpress.bluetooth.helpers.characteristic.FPCharacteristic;
    import ru.flashpress.bluetooth.helpers.characteristic.FPCharacteristicValueFormat;
    import ru.flashpress.bluetooth.helpers.characteristic.stream.FPStreamIn;
    import ru.flashpress.bluetooth.helpers.peripheral.FPPeripheral;
    import ru.flashpress.bluetooth.helpers.service.FPService;
    import ru.flashpress.bluetooth.helpers.service.FPServiceEvent;
    import ru.flashpress.bluetooth.managers.central.FPCentralManager;
    import ru.flashpress.bluetooth.managers.central.FPcmScanOptions;

    public class CentralView extends Sprite
    {
        public static const SERVICE_UUID:String = 'E20A39F4-73F5-4BC4-A12F-17D1AD07A961';
        public static const CHARACTERISTIC_UUID:String = '08590F7E-DB05-467E-8757-72F6FAEB13D4';
        //
        public function CentralView()
        {
            var options:FPBluetoothOptions = new FPBluetoothOptions();
            options.nativeLogEnabled = true;
            FPBluetooth.init(options);
            //
            startBluetooth();
        }


        // Bluetooth Methods ****************

        private var cm:FPCentralManager;
        private function startBluetooth():void
        {
            trace('startBluetooth');
            var queue:FPQueueData = new FPQueueData('ru.flashpress.chat.central', FPQueueTypes.SERIAL);
            cm = new FPCentralManager(null, queue);
            cm.addEventListener(FPBluetoothEvent.UPDATE_STATE, updateStateHandler);
            cm.addEventListener(FPCentralManagerEvent.PERIPHERAL_DISCOVER, discoverPeripheralHandler);
        }

        private function updateStateHandler(event:FPBluetoothEvent):void
        {
            trace('updateStateHandler', event.state);
            if (event.state != FPbtState.POWERED_ON) {
                return;
            }
            var options:FPcmScanOptions = new FPcmScanOptions(true, null);
            cm.startScan(options, SERVICE_UUID);
        }

        private var peripheral:FPPeripheral;
        private function discoverPeripheralHandler(event:FPCentralManagerEvent):void
        {
            trace('discoverPeripheralHandler', event.peripheral);
            if (peripheral) return;
            peripheral = event.peripheral;
            trace(' name:', peripheral.advertisementInited ? peripheral.advertisementInited.localName : null);
            //
            peripheral.addEventListener(FPPeripheralEvent.CONNECTED, peripheralConnectedHandler);
            peripheral.addEventListener(FPPeripheralEvent.DISCONNECT, peripheralDisconnectedHandler);
            peripheral.connect();
        }

        private function peripheralConnectedHandler(event:FPPeripheralEvent):void
        {
            trace('peripheralConnectedHandler');
            peripheral.discoverServiceUUIDs(SERVICE_UUID);
            peripheral.addEventListener(FPPeripheralEvent.DISCOVER_SERVICES, discoverServicesHandler);
        }
        private function peripheralDisconnectedHandler(event:FPPeripheralEvent):void
        {
            trace('peripheralDisconnectedHandler');
            peripheral.removeEventListener(FPPeripheralEvent.CONNECTED, peripheralConnectedHandler);
            peripheral.removeEventListener(FPPeripheralEvent.DISCONNECT, peripheralDisconnectedHandler);
            peripheral = null;
        }

        private var service:FPService;
        private function discoverServicesHandler(event:FPPeripheralEvent):void
        {
            trace('discoverServicesHandler');
            if (event.error) {
                trace('discoverServicesHandler, error:', event.error);
                return;
            }
            //
            service = peripheral.services.list[0];
            trace(' service:', service);
            //
            service.discoverCharacteristicUUIDs(CHARACTERISTIC_UUID);
            service.addEventListener(FPServiceEvent.DISCOVER_CHARACTERISTICS, discoverCharacteristicsHandler);
        }

        public var characteristic:FPCharacteristic;
        private var streamIn:FPStreamIn;
        private function discoverCharacteristicsHandler(event:FPServiceEvent):void
        {
            trace('discoverCharacteristicsHandler');
            if (event.error) {
                trace('discoverCharacteristicsHandler, error:', event.error);
                return;
            }
            characteristic = service.characteristics.list[0];
            trace(' characteristic:', characteristic);
            characteristic.initValueFormat(FPCharacteristicValueFormat.MESSAGES);
            streamIn = characteristic.streamIn;
            characteristic.setNotify(true);
            characteristic.addEventListener(FPCharacteristicEvent.UPDATE_NOTIFICATION, updateNotificationHandler);
            //
            characteristic.addEventListener(FPCharacteristicEvent.UPDATE_MESSAGES, updateMessageHandler);
        }

        private function updateNotificationHandler(event:FPCharacteristicEvent):void
        {
            trace('updateNotificationHandler:', event.isNotifying);
        }

        private function updateMessageHandler(event:FPCharacteristicEvent):void
        {
            trace('updateMessageHandler');
            trace(' error:', event.error);
            trace(' messages:', event.messages);
        }
    }
}

周边经理:


package
{
    import flash.display.Sprite;

    import ru.flashpress.bluetooth.FPBluetooth;
    import ru.flashpress.bluetooth.constants.FPbtState;
    import ru.flashpress.bluetooth.data.FPAdvertisementData;
    import ru.flashpress.bluetooth.data.FPBluetoothOptions;
    import ru.flashpress.bluetooth.events.FPBluetoothEvent;
    import ru.flashpress.bluetooth.events.FPCharacteristicEvent;
    import ru.flashpress.bluetooth.events.FPPeripheralManagerEvent;
    import ru.flashpress.bluetooth.helpers.characteristic.FPCharacteristic;
    import ru.flashpress.bluetooth.helpers.characteristic.FPCharacteristicPermissions;
    import ru.flashpress.bluetooth.helpers.characteristic.FPCharacteristicProperties;
    import ru.flashpress.bluetooth.helpers.characteristic.FPCharacteristicValueFormat;
    import ru.flashpress.bluetooth.helpers.service.FPService;
    import ru.flashpress.bluetooth.managers.peripheral.FPPeripheralManager;

    public class PeripheralView extends Sprite
    {
        public static const SERVICE_UUID:String = 'E20A39F4-73F5-4BC4-A12F-17D1AD07A961';
        public static const CHARACTERISTIC_UUID:String = '08590F7E-DB05-467E-8757-72F6FAEB13D4';
        //
        public function PeripheralView()
        {
            var options:FPBluetoothOptions = new FPBluetoothOptions();
            options.nativeLogEnabled = true;
            FPBluetooth.init(options);
            //
            startBluetooth();
        }

        // Bluetooth Methods ****************

        private var pm:FPPeripheralManager;
        private function startBluetooth():void
        {
            trace('startBluetooth');
            pm = new FPPeripheralManager();
            pm.addEventListener(FPBluetoothEvent.UPDATE_STATE, updateStateHandler);
            pm.addEventListener(FPPeripheralManagerEvent.ADD_SERVICE, addServiceHandler);
        }

        private var characteristic:FPCharacteristic;
        private var service:FPService;
        private function updateStateHandler(event:FPBluetoothEvent):void
        {
            trace('updateStateHandler:', event.state);
            if (event.state != FPbtState.POWERED_ON) {
                return;
            }
            //
            var properties:uint = FPCharacteristicProperties.NOTIFY;
            var permissions:uint = FPCharacteristicPermissions.WRITEABLE;
            var valueFormat:uint = FPCharacteristicValueFormat.MESSAGES;
            characteristic = new FPCharacteristic(CHARACTERISTIC_UUID, properties, permissions, valueFormat);
            characteristic.addEventListener(FPCharacteristicEvent.SUBSCRIBED_TO_CENTRAL, subscribedToCentralHandler);
            characteristic.addEventListener(FPCharacteristicEvent.UNSUBSCRIBED_FROM_CENTRAL, unsubscribedFromCentralHandler);
            characteristic.notifyMTU = 50;
            //
            service = new FPService(SERVICE_UUID, true);
            service.addCharacteristic(characteristic);
            //
            pm.addService(service);
        }
        private function addServiceHandler(event:FPPeripheralManagerEvent):void
        {
            trace('addServiceHandler');
            if (event.error) {
                trace(' error:', event.error);
                return;
            }
            if (!pm.isAdvertising) {
                var uuids:Vector. = new [SERVICE_UUID];
                var advertisementData:FPAdvertisementData = new FPAdvertisementData('My Local name', uuids);
                pm.startAdvertising(advertisementData);
            }
        }

        private function unsubscribedFromCentralHandler(event:FPCharacteristicEvent):void
        {
            trace('unsubscribedFromCentralHandlers', event.central);
        }
        private function subscribedToCentralHandler(event:FPCharacteristicEvent):void
        {
            trace('subscribedToCentralHandler', event.central);
            //
            characteristic.sendMessage('send my message');
        }
    }
}
于 2015-03-17T11:11:34.753 回答
0

您可以使用 LAN NetGroup 方法在没有 Cirrus 的情况下使用 RTMFP。

此方法在以下文档中进行了描述NetConnection/connect()

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetConnection.html#connect()

可以在这里找到一个很好的例子:

http://tomkrcha.com/?p=1803

private var connection:NetConnection;
private var group:NetGroup;

private function connect():void {
    connection = new NetConnection();
    connection.connect("rtmfp:");
    connection.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
}

private function netStatus(event:NetStatusEvent):void {
    switch(event.info.code){
        case "NetConnection.Connect.Success":
            joinGroup();
            break;
        case "NetGroup.Posting.Notify":
            receive(event.info.message);
            break;
    }
}

private function joinGroup():void{
    var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/groupOne");
    groupspec.postingEnabled = true;
    groupspec.ipMulticastMemberUpdatesEnabled = true;
    groupspec.addIPMulticastAddress("225.225.0.1:30303");

    group = new NetGroup(connection, groupspec.groupspecWithAuthorizations());
    group.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
}

public function send(text:String):void {
    var message:Object = {
        sender: connection.nearId,
        text: text
    }
    group.post(message);
}

public function receive(message:Object):void {
    trace("Received message from " + message.sender + ": " + message.text);
}

这是我体验过的在本地网络上执行多用户应用程序的最简单方法,因为它不需要服务器(甚至发现邻居),只需要 Flash Player。

于 2015-01-23T17:46:54.577 回答