Home >Database >Mysql Tutorial >[cocos2d-x]Cocos2d-x游戏截屏

[cocos2d-x]Cocos2d-x游戏截屏

WBOY
WBOYOriginal
2016-06-07 15:32:251158browse

很多时候,我们的游戏可能要做分享到微博或者一些社区,当分享的内容仅仅是一些文字的话,可能效果不是很ok,如果在分享内容能加上 游戏的截图就非常nice了,比如捕鱼达人中抓到大鲨鱼,酷跑中得第一名,我相信那一瞬间的游戏画面对你来说相当的珍贵,so,我

很多时候,我们的游戏可能要做分享到微博或者一些社区,当分享的内容仅仅是一些文字的话,可能效果不是很ok,如果在分享内容能加上

游戏的截图就非常nice了,比如捕鱼达人中抓到大鲨鱼,酷跑中得第一名,我相信那一瞬间的游戏画面对你来说相当的珍贵,so,我们怎样才能

将游戏的当前图像截取出来呢,直接上代码吧:


void YourClassName::SaveScreenshot()
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCRenderTexture* texture = CCRenderTexture::create((int)size.width, (int)size.height);    
    texture->setPosition(ccp(size.width/2, size.height/2));    
    texture->begin();
    CCDirector::sharedDirector()->getRunningScene()->visit();
    texture->end();
    texture->saveToFile("screenshot.png", kCCImageFormatPNG);
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Qt之2D绘图Next article:SOAP1.1和SOAP1.2的区别