将“Cocos2dx-截屏并设置图片尺寸 ”中cocos2d-x代码转换为2.2的代码

时间:2021-11-19 23:31:15

Cocos2dx-截屏并设置图片尺寸: http://www.cocos2dev.com/?p=522

2.2 代码如下:

void HelloWorld::screenShoot()
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCRenderTexture *texture = CCRenderTexture::create(winSize.width/2, winSize.height/2, kCCTexture2DPixelFormat_RGBA8888);
    CCScene *curScene = CCDirector::sharedDirector()->getRunningScene();
    CCPoint point = curScene->getAnchorPoint();
    texture->begin();
    curScene->setScale(0.5f);
    curScene->setAnchorPoint(ccp(0, 0));
    curScene->visit();
    texture->end();
    
    texture->saveToFile("screenShoot.png", kCCImageFormatPNG);
    
    curScene->setScale(1.0f);
    curScene->setAnchorPoint(point);
//    CC_SAFE_DELETE(curScene);
}