Last active
March 9, 2016 09:58
-
-
Save tadamatu/657a90059382f0ba8eee to your computer and use it in GitHub Desktop.
cocos2d-xでスクリーンショットをとってシェアする機能を実装する ref: http://qiita.com/tadamatu/items/ec26316822b73d66df30
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 取得したテクスチャを保存する | |
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()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 取得したテクスチャを保存する | |
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()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// スクリーンショットを取得し、ツイートする | |
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