Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cocos2d-x x iBeacon

Avatar for Tomoo Kaku Tomoo Kaku
August 20, 2014
140

Cocos2d-x x iBeacon

Bluetoothを使ったゲームを作ろう

Avatar for Tomoo Kaku

Tomoo Kaku

August 20, 2014
Tweet

Transcript

  1. ࣗݾ঺հ • Tomoo Kaku • ΞΫηϧϚʔΫגࣜձࣾ γχΞΤΩεύʔτ ήʔϜϑϨʔϜϫʔΫͷઃܭɾ։ൃ ݱࡏɺCocos2d-xͷήʔϜͷج൫पΓΛ୲౰ͯ͠ ͍·͢ɻ

    • iOS /AndroidΞϓϦΛར༻ͨ͠αʔϏεͷاըɺ ઃܭɺ։ൃ • Objective-CɺC/C++ɺJavaɺRubyɺPHPͰ։ൃ
  2. iBeaconͰͰ͖Δ͜ͱ iOSͰ͸Core Location Frameworkʹ௥Ճ͞Εͨ ·ͨɺMultipeer Connectivity FrameworkͰ΋ར༻ ͞Ε͍ͯΔ • BeaconͷྖҬ؍ଌʢRegionʣ

    • Beaconͷڑ཭؍ଌʢRangingʣ • iOS7.1͔Β͸ΞϓϦ͕ىಈ͍ͯ͠ͳͯ͘΋ػೳ ͢ΔɻϩʔΧϧ௨஌ػೳʹରԠ
  3. iBeaconΛ࢖ͬͨήʔϜΛ࡞Γ͍ͨʢ̎ʣ • ͳͷͰɺࠓճ͸ɺiOS <-> Android͸ఘΊͯɺiOS <-> iOSͱAndroid <-> AndroidͰP2PʹରԠͨ͠ ήʔϜʹ͢Δ

    • Android͸Classic BluetoothͰɻɻɻ ͦͷ୅ΘΓ΄ͱΜͲͷ୺຤Ͱ࢖͑Δ • কདྷɺAndroidͷBLEͰϖϦϑΣϥϧϞʔυ͕࢖ ͑Δ༷ʹͳͬͨΒϋοϐʔɻ
  4. Cocos2d-xͰBluetoothͷར༻ʢ̎ʣ • iOS͸Core LocationɺCore BluetoothɺMultipeer ConnectivityΛ࢖༻ • Android͸Classic BluetoothΛ࢖༻ Classic

    Bluetoothͱ͸BLEͰ͸ͳ͍Bluetooth 2.1 ΍3.0ͳͲɻϖΞϦϯάͳ͠Ͱར༻ API Level 10ʢAndroid 2.3.3ʣҎ߱
  5. CCBluetooth CCBluetooth.h #define RESULT_NOTFOUND_PEER 0 #define RESULT_RECEIVE_MESSAGE 1 #define STATUS_ERROR

    -1 #define STATUS_OK 1 class CCBluetoothDelegate { public: virtual void onResult(int resultCode, int status, const char *error, const char *peerID, const char *message) {}; }; class CCBluetooth { public: CCBluetooth(CCBluetoothDelegate* delegate); ~CCBluetooth(); void start(const char *peerID, const char *message); void stop(); private: CCBluetoothDelegate *_delegate; };
  6. CCBluetooth Function // ։࢝ void start( const char *peerID, //

    Ϣʔβ(୺຤)Λࣝผ const char *message // ઀ଓޙʹૹΔσʔλ ); // ऴྃ void stop();
  7. CCBluetooth CCBluetoothDelegate void onResult( int resultCode, // ݁Ռ int status,

    // εςʔλε const char *error, // Τϥʔ಺༰ const char *peerID, // ૬खͷID const char *message // ड͚औͬͨσʔλ );
  8. αϯϓϧίʔυ SampleScene.cpp void SampleScene::onEnter() { cocos2d::CCLayer::onEnter(); bluetooth = new bluetooth_plugin::CCBluetooth(this);

    bluetooth->start("<PeerID>", "<message>"); } void SampleScene::onExit() { cocos2d::CCLayer::onExit(); bluetooth->stop("<PeerID>", "<message>"); } // CCBluetoothDelegate void SampleScene::onResult( int resultCode, int status, const char *error, const char *peerID, const char *message) { CCLOG("૬ख: %s", peerID.c_str()); CCLOG("ϝοηʔδ: %s", message.c_str()); }