微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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;

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐