关于cocos2dx RenderTexture的newImage为空

前端之家收集整理的这篇文章主要介绍了关于cocos2dx RenderTexture的newImage为空前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
	Sprite* spr1 = Sprite::create("spr1.png");
	spr1->retain();//在3.0此处必须写上这个
        auto render = RenderTexture::create(visibleSize.width,visibleSize.height,Texture2D::PixelFormat::RGBA8888);
	render->retain();
	render->beginWithClear(0,255);

	spr1->visit();
	render->end();

	Director::getInstance()->getRenderer()->render();//在3.0此处必须写上这个,否则newImage整张图片都为黑色,或者在下一帧获取

	char jpg2[20];
	sprintf(jpg2,"image-%d.jpg",123);
	std::string fullpath1 = FileUtils::getInstance()->getWritablePath() + jpg2;
	Image* image1 = render->newImage();
	image1->saveToFile(fullpath1,true);  //设置保存目录和文件名
	image1->release();
原文链接:https://www.f2er.com/cocos2dx/345802.html

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