cocos2d-x 讲节点渲染成图片

前端之家收集整理的这篇文章主要介绍了cocos2d-x 讲节点渲染成图片前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

bool WorldWindow::saveSpriteImg(const std::string& fileName)

{

bool flag = false;

Size wsize = Director::getInstance()->getWinSize();

CCRenderTexture *texture = CCRenderTexture::create(wsize.width,wsize.height,Texture2D::PixelFormat::RGBA8888,GL_DEPTH24_STENCIL8);

texture->setPosition(ccp(0,0));

texture->ignoreAnchorPointForPosition(true);

texture->setAnchorPoint(CCPointZero);

texture->beginWithClear(0.0f,0.0f,0.0f);

// -- start 需要渲染的节点/Users/topgame1602/Desktop/saveSpriteImg.js

Node *n = _uiMainNode->getNodeByName("UI");

n->visit();

// -- end

texture->end();

// 当前渲染的节点

texture->saveToFile("aa1.png",kCCImageFormatPNG,true,[=](RenderTexture* t,const std::string& s){

CCLog("%s",s.c_str());

});

return flag;

}

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