ãã®è¨äºã¯
cocos2d-x Advent Calendar1æ¥ç®ã®è¨äºã§ãã
cocos2d-x Advent Calendar 2015 - Qiita
誰ãç«ã¦ã¦ãªãã®ã§ç«ã¦ã¦ã¿ã¾ããããä»å¹´ã¯åå è ãå°ãªããçä¸æ°å³ãªã®ã§ãèå³ã®ããæ¹ã¯ãã²åå ãã¦ã¿ã¦ãã ããã
Qiitaã®Advent Calendarãªã®ã§ãQiitaã§æ¸ããæ¹ãè¦ããããã¨æã£ãã®ã§ãããèªåã®ä½ã£ãç©ãçºä¿¡ããå ´ã¨ãã¦ã¯Qiitaã¯ä¸é©ã ã¨æããããã°ã«æ¸ããã¨ã«ãã¾ããã
ã½ã¼ã·ã£ã«é£æºç¨ã®ãã©ã°ã¤ã³ä½ã£ã
ä»åã¯CCSocialShareã¨ããcocos2d-xããç°¡åã«Twitter/Facebookã«æ稿ã§ãããã©ã°ã¤ã³ãä½ã£ã¦ã¿ãã®ã§ãç´¹ä»ãã¾ãã
cocos2d-xã§TwitterãFacebookã«ã¹ã¯ãªã¼ã³ã·ã§ãããªã©ãæ稿ãããï¼ã¨ããéè¦ã¯é«ãã¯ãã ãã©ãã©ãã«ãå ±éåãããä¸æãä»çµã¿ãè¦ã¤ãããªãã
cocos2d-xãå ¬å¼ã§æä¾ããã¦ããplugin-xã¨ãããã©ã°ã¤ã³ã§ãã½ã¼ã·ã£ã«é£æºæ©è½ãæä¾ããã¦ããããã©ãçµã¿è¾¼ã¿æ¹ãç ©éã ã£ãããOSæ¨æºã®æ©è½ã使ã£ã¦ããªãããã使ãåæãæªãæãã§ããã
plugin-xã§ã¯ãèªè¨¼ã«ç¬èªã®æ©æ§ã使ã£ã¦ãã¦ããã¡ãã¡oAuthèªè¨¼ãããªãã¨ãããªãã£ããã§é常ã«é¢åãiOSã®å ´åã¯æ¨æºã®ä»çµã¿ã使ãããï¼
ã¨ããããã§ã以åãªãªã¼ã¹ãã ãWave Weaverã ãªã©ã«ä½¿ã£ã¦ããã³ã¼ããåãåºãã¦æ±åãã¦ã¿ãã
ã究極ãã£ã¦ããã®ã¯è¥å¹²èªå¼µãå ¥ã£ã¦ãããã©ãè¨ã£ãç©åã¡ã ã¨æã£ã¦ãã
使ãæ¹
#include "CCSocialManager.h" void onShareButtonTapped() { if (CCSocialShare::SocialManager::isAvailable(CCSocialShare::Service::TWITTER)) { CCSocialShare::SocialManager::postMessage(CCSocialShare::Service::TWITTER, "I beat this game!", path.c_str(), [](CCSocialShare::PostResult result) { if (result == CCSocialShare::PostResult::SUCCEED) { // When to post is succeed log("Done"); } else if (result == CCSocialShare::PostResult::CANCELED) { // When to post is canceled log("Canceled"); } }); } }
ãããªæãã§SocialManager::postMessage
ãå¼ã¹ã°iOS/Androidããç°¡åã«ä½¿ããã渡ãå¼æ°ã«ãã£ã¦Twitter/Facebookã«å¯¾å¿ãã¦ããã
iOSã®å ´åããã®ããã«æ¨æºã®å ±ææ©è½ãç«ã¡ä¸ãããããæ¢ã«è¨å®ããã¦ããã°å³åº§ã«ã¤ã¶ãããã
Androidã¯ã¤ã³ãã³ãã使ã£ã¦ãTwitter/Facebookã¢ããªãèµ·åã§ããããããã¡ããèªè¨¼ä¸è¦ã
ã³ã¼ã«ããã¯ã«ã対å¿ãã¦ãããããã©ã ãå¼ã渡ãã¨ãæ稿ãããããã£ã³ã»ã«ããå¾ã«ãªãããã®å¦çãããããã¨ãã§ãããï¼iOSã®ã¿ï¼
ãã¡ã¤ã«ãã¹ã渡ãã°ç»åæ·»ä»ãè¡ãããä¾ãã°åç´ã«ã¹ã¯ãªã¼ã³ã·ã§ãããå ±æããã ããªã以ä¸ã®éãã
#include "CCSocialManager.h" void onShareButtonTapped() { if (CCSocialShare::SocialManager::isAvailable(CCSocialShare::Service::TWITTER)) { Size size = Director::getInstance()->getWinSize(); RenderTexture* texture = RenderTexture::create((int)size.width, (int)size.height); texture->setPosition(Point(size.width / 2, size.height / 2)); texture->begin(); Director::getInstance()->getRunningScene()->visit(); texture->end(); texture->saveToFile("screenshot.png", Image::Format::PNG, true, [&](RenderTexture* rt, const std::string& path) { CCSocialShare::SocialManager::postMessage(CCSocialShare::Service::TWITTER, "I beat this game!", path.c_str(), [](CCSocialShare::PostResult result) { if (result == CCSocialShare::PostResult::SUCCEED) { // When to post is succeed log("Done"); } else if (result == CCSocialShare::PostResult::CANCELED) { // When to post is canceled log("Canceled"); } }); }); } }
æ¢ãã¦ç»åã縮å°ããæ©è½ãªã©ã¯å®è£ ãã¦ããªããå®éã«ãã®ããã«ãã¦ã¹ã¯ãªã¼ã³ã·ã§ãããæ·»ä»ãã¦ãã¾ãã¨å¤§ããããã®ã§ãå¿ è¦ã«å¿ãã¦ç¸®å°ããã¨è¯ãã¨æãã
çµã¿è¾¼ã¿æ¹æ³
https://github.com/giginet/CCSocialShare/blob/master/README.md#how-to-integrate
iOS/Androidã¸ã®çµã¿è¾¼ã¿æ¹æ³ã¯ä¸è¨ã®READMEã«æ¸ãã¦ããã®ã§ããã®éãã«çµã¿è¾¼ãã°è¯ãã¨æãã
iOS
iOSã¯SocialManager.{h,mm}
ã¨Social.framework
ãããã¸ã§ã¯ãã«èªã¾ããã°ç°¡åã«ä½¿ããã便å©ã
Android
Androidã¯Android Studio + Gradleãç¨ãã¦ãã«ãããããã«è¨è¨ãã¦ããã
éçã©ã¤ãã©ãªããã«ãããããã®Android.mk
ã¨ãAndroidã¢ããªå´ã«çµã¿è¾¼ãããã®build.gradle
両æ¹ã®æ´æ°ãå¿
è¦ã§ããã«ããããããè¡ããªãã¨ãããªããããiOSã«æ¯ã¹ã¦ç
©éã«ãªã£ã¦ããã
æ§æ¥ã®Antã使ã£ããã«ãã®ããã¥ã¡ã³ãã¯æ¸ãã¦ããªããã©ãä¸æãæãã«ããã°ãã«ãã§ããã¨æãã
ä»å¾
Androidã§ã®ã³ã¼ã«ããã¯å¯¾å¿
ç¾å¨ãAndroidçã§ã¯ã³ã¼ã«ããã¯ãå¼ã¶æ©æ§ã«å¯¾å¿ãã¦ããªããå®è£ ã®ç®å¦ã¯ä»ãããã以ä¸ã®ãããªçç±ã§é害ãå¤ãã¦å®è£ ããã¦ããªãã
JNIããC++ã®é¢æ°ãã¤ã³ã¿ãå©ãã®ã大å¤
è¯ãæ¹æ³ãè¦ã¤ãããªãã£ããJNIåãä½ãã
ã¤ã³ãã³ãçµäºã®ã³ã¼ã«ããã¯æã®è¨è¨
ã¤ã³ãã³ããçµäºãããã¨ã®æ¤ç¥ã¯Activityã§ããã®ãä¸è¬çãªããã§ãçµã¿è¾¼ãéã«Cocos2dxActivity
ãæ¸ãæããå¿
è¦ãåºã¦ãã¦ãçµã¿è¾¼ã¿ã®æéãå¢ãã¦ãã¾ãã
Androidçã®å®è£ ã«ã¯æ§æ¥ã®ã¤ã³ãã³ãã®ä»çµã¿ãç¨ãã¦ãããã ãã©ãä¾ãã°Support Libraryã®ShareCompatãªã©ãå©ç¨ããã°ããã«ã¹ãã¼ãã«å®è£ ã§ãããããããªãã
Android+JNIåãé«ãæ¹ããã®Pull Requestãå¾ ã¡ãã¦ãã¾ã ð
CIããã
Android/iOSã¯ãã¹ãã©ãããã©ã¼ã ã§ç¢ºèªããã®ã大å¤é¢åã ã£ãã®ã§CIç°å¢ãæ´åãããæãã
cocos2d-xãsubmoduleã¨ãã¦èªãã§ãã¦ãã¢ã¢ããªããã«ãããæããè¯ãããªãã¨èãã¦ãã¾ãã
ã©ãããå©ç¨ãã ãã
以ä¸ããå°å ¥ã§ãã¾ãï¼ï¼ï¼
ã¤ã³ã¿ã¼ãã§ã¤ã¹ãªã©ã¯äºåãªãå¤æ´ãããå¯è½æ§ãããã¾ãã
cocos2d-xã§ã²ã¼ã ãä½ãããæ¹ã¯
æèã§ã¯ãããã¾ããããã²ãã¡ãã®æ¬ã§å ¥éãã¾ãããã
ä½µãã¦Advent Calendarã«ãåå ããã ããã¨å¹¸ãã§ãã
ããããçºå£²ãã1å¹´ãçµã¤ãã§ããã
ã¤ãã§ã«ã²ã¼ã ããããã
æè¿æ°ä½ãåºãã¦ããªãã®ã§ããã以ååºããã²ã¼ã ãè²¼ã£ã¦ããã¾ãããèå³ã®ããæ¹ã¯ãã²ã
https://itunes.apple.com/jp/app/wave-weaver/id841280819?mt=8&uo=4&at=10l8JW&ct=hatenablog