@H_301_1@实现这个功能时候,在网上查了一些方法,http://www.cocoachina.com/bbs/read.PHP?tid-277669-page-1.html@H_301_1@这个论坛里面有个人用renderTexture->setVirtualViewport()来实现,没看懂(后面慢慢研究),看了一些回复后,自己想了个笨方法,如下:
@H_301_1@auto winSize = Director::getInstance()->getWinSize();
auto origin = Director::getInstance()->getVisibleOrigin();
RenderTexture *renderTexture = RenderTexture::create(winSize.width,winSize.height);
//这里截取整个屏幕
renderTexture->begin();
Director::getInstance()->getRunningScene()->visit();
renderTexture->end();
@H_301_1@Rect shootArea(winSize.width - 200,winSize.height - 200,200,200);
@H_301_1@auto sp = renderTexture->getSprite();
sp->setTextureRect(shootArea);
//显示截取要的部分
//sp->removeFromParent();
//this->addChild(sp,222);
sp->setPosition(sp->getContentSize()/2);
RenderTexture *renderTexture2 = RenderTexture::create(shootArea.size.width,shootArea.size.height);
renderTexture2->begin();
sp->visit();
renderTexture2->end();
if (renderTexture2->saveToFile("screen_shot.png",Image::Format::PNG))
{
//保存在这个路径FileUtils::sharedFileUtils()->getWritablePath()
CCLOG("screenshot success");
}
else
{
CCLOG("screenshot Failed");
}