如何在cocos2dx 3.3中截取场景的截图?

时间:2014-11-19 06:35:53

标签: c++ ios iphone cocos2d-x cocos2d-x-3.0

我正在开发一款游戏,我想拍摄场景截图..如何在cocos2dx 3.3中实现?请告诉我

我的代码在下面给出

    CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
    CCRenderTexture * tex = CCRenderTexture::create(screenSize.width, screenSize.height);
    tex->setPosition(ccp(screenSize.width/2, screenSize.height/2));

    tex->begin();
    this->getParent()->visit();
    tex->end();

    tex->saveToFile("Image_Save.png", kCCImageFormatPNG);

2 个答案:

答案 0 :(得分:2)

使用此

utils::captureScreen( CC_CALLBACK_2(GameScene::afterCaptured, this), "screenshot.png");

//callback function

void GameScene::afterCaptured(bool succeed, const std::string &outputFile)
{    
    if (succeed) {
        log(" screen shot%s", outputFile.c_str());
    }
} 

答案 1 :(得分:0)

只需替换

tex->saveToFile("Image_Save.png", Image::Format::PNG); 

而不是

tex->saveToFile("Image_Save.png", kCCImageFormatPNG);

这肯定可以帮到你