Skip to content

Instantly share code, notes, and snippets.

@tadamatu
Last active March 9, 2016 09:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadamatu/657a90059382f0ba8eee to your computer and use it in GitHub Desktop.
Save tadamatu/657a90059382f0ba8eee to your computer and use it in GitHub Desktop.
cocos2d-xでスクリーンショットをとってシェアする機能を実装する ref: http://qiita.com/tadamatu/items/ec26316822b73d66df30
// 取得したテクスチャを保存する
texture->saveToFile("screenshot.png", Image::Format::PNG);
// パスを取得し、ツイートをする
std::string path = FileUtils::getInstance()->getWritablePath().append("screenshot.png");
NativeCodeLauncher::postTwitter("ツイート内容", "http://tadamatu.blogspot.jp/", path.c_str());
// 取得したテクスチャを保存する
texture->saveToFile("screenshot.png", Image::Format::PNG);
// パスを取得し、ツイートをする
std::string path = FileUtils::getInstance()->getWritablePath().append("screenshot.png");
NativeCodeLauncher::postTwitter("ツイート内容", "http://blog.tadamatuapps.com/", path.c_str());
// スクリーンショットを取得し、ツイートする
void screenShot() {
// スクリーンショットのテクスチャを取得する
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) {
// 保存完了のコールバック処理
// ツイートをする
NativeCodeLauncher::postTwitter("ツイート内容", "http://blog.tadamatuapps.com/",path.c_str());
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment