CCSocialShare
provides the feature to share for your games on cocos2d-x.
- Multi platforms (iOS/Android)
- Multi services (Twitter/Facebook)
- Easy to integrate
- Easy to share
- SocialKit (iOS)
- Intent (Android)
- Image attachment
- Compatible with Android Studio
- Callback function
#include "CCSocialManager.h"
void onShareButtonTapped() {
if (CCSocialShare::SocialManager::isAvailable(CCSocialShare::Service::TWITTER)) {
CCSocialShare::SocialManager::postMessage(CCSocialShare::Service::TWITTER,
"I beat this game!",
[](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");
}
});
}
}
#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");
}
});
});
}
}
- Latest Xcode (7.0+)
- cocos2d-x 3.x
- Latest Android Studio (1.5+)
- cocos2d-x 3.7+
- Because of Android Studio support.
$ cocos new YourFantasticGame -l cpp
$ cd YourFantasticGame
$ git clone https://github.com/giginet/CCSocialShare.git Classes/external/CCSocialShare
- Add
CCSocialManager.{h,mm}
into your Xcode project. - Add
Social.framework
- Target 'YourFantasticGame iOS' > General > Linked Frameworks and Libraries
- Build and Run
1: Open proj.android-studio
with Android Studio
2: Edit proj.android-studio/settings.gradle
like following
include ':libcocos2dx'
project(':libcocos2dx').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/libcocos2dx')
include ':YourFantasticGame'
project(':YourFantasticGame').projectDir = new File(settingsDir, 'app')
// Add this setting
include ':socialshare'
project(':socialshare').projectDir = new File(settingsDir, '../Classes/external/CCSocialShare/CCSocialShare/android')
3: Edit proj.android-studio/app/build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libcocos2dx')
// Add this line
compile project(':socialshare')
}
4: Edit proj.android-studio/app/jni/Android.mk
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../../Classes/AppDelegate.cpp \
../../../Classes/HelloWorldScene.cpp \
../../../Classes/external/CCSocialShare/CCSocialShare/android/CCSocialManager.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes \
$(LOCAL_PATH)/../../../Classes/external/CCSocialShare/CCSocialShare
5: Edit proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java
to execute callback function.
import org.kawaz.socialshare.SocialShare;
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
SocialShare.onActivityResult(resultCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
6: Execute following command
$ cocos compile -p android --android-studio
7: Build and Run on Android Studio