cocos2dx截取指定区域的屏幕

前端之家收集整理的这篇文章主要介绍了cocos2dx截取指定区域的屏幕前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

@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@//截取的指定区域

@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");
}

@H_301_1@谁有其他更好的方法说一下

原文链接:https://www.f2er.com/cocos2dx/341070.html

猜你在找的Cocos2d-x相关文章