cocos2d-x 屏幕截图

void A::screenShoot()
{
    //定义一个屏幕大小的渲染纹理
    CCRenderTexture* renderTexture = CCRenderTexture::create(m_visibleSize.width * .5, m_visibleSize.height * .5, CCTexture2DPixelFormat::kTexture2DPixelFormat_RGBA8888);

    CCScene * curScene = CCDirector::sharedDirector()->getRunningScene();
    CCPoint ancPos = curScene->getAnchorPoint();

    //渲染纹理开始捕捉
    renderTexture->begin();

    // 缩小屏幕截屏区域
    curScene->setScale(.5);
    curScene->setAnchorPoint(CCPoint(0, 0));

    //绘制当前场景
    curScene->visit();

    //结束
    renderTexture->end();

    //保存png
    renderTexture->saveToFile("screenshoot.png", tCCImageFormat::kCCImageFormatPNG);

    // 恢复屏幕尺寸
    curScene->setScale(1);
    curScene->setAnchorPoint(ancPos);
    //CC_SAFE_DELETE(curScene);
}

 

转自:http://www.cocos2dev.com/?p=522

posted @ 2014-10-14 17:01  猿走天下  阅读(304)  评论(0编辑  收藏  举报