最近在使用 cc.RenderTexture 的时候,遇到一个这样的问题。
我用 cc.RenderTexture 做截图,然后可以把截取到的图片,赋值给 sprite 显示出来
spriteFrame.setTexture(renderTexture);
这个没问题。
现在我需要不停的截取图片,假设是 3次。每次截图内容都不一样。我想把他们都渲染出来。一个办法是搞 3个 spriteframe,这个肯定没问题。
但是后面如果不是3次是很多次的话,这个做法就不好了。
然后我发现 cc.RenderTexture 里面有 drawTextureAt 方法。
于是我就是了下,创建了个新的 cc.RenderTexture , 然后把每次截到的纹理调用 drawTextureAt 画到新的 cc.RenderTexture 上。
但是屏幕上什么都没有。
然后我看了下源码,发现 drawTextureAt 接受的 texture 貌似有要求
drawTextureAt (texture, x, y) {
if (!texture._image || texture._image.width === 0) return;
// ......
},
因为我打印了 _image 这个属性是 null。但如果是一个用 .png 图片的 sprite 的话,就可以正常 drawTextureAt ,因为它的 _image 是有值的 [object ImageBitmap]。
想问下有什么办法解决不?
