Cocos Creator原生App截图白屏解决方案
时间:2021-09-30 16:18:24 +0800 CST 浏览:3227

Cocos Creator打包原生App截图白屏解决方案

我们一般是采用cc.RenderTexture来截图并保存到游戏的可写目录。有时候会遇上,截出来的图片是白屏,或者部分白屏。

经过多方测试,我们发现,是Mask的锅,用了cc.Mask的界面,截图的时候,就会遇上这样的问题。

如果遇上这样的问题,只需要检查你的cc.RenderTexture初始化的时候,是否少了参数。最主要的是第三个参数,一定要是RGBA8888

var texture = new cc.RenderTexture(w, h, cc.Texture2D.PIXEL_FORMAT_RGBA8888, gl.DEPTH24_STENCIL8_OES);

完整示例如下:

function captureScreen(){
    var size = cc.director.getWinSize();
    var fileName = "result_share.jpg";
    var fullPath = jsb.fileUtils.getWritablePath() + fileName;
    if (jsb.fileUtils.isFileExist(fullPath)) {
        jsb.fileUtils.removeFile(fullPath);
    }
    var width = Math.floor(size.width);
    var height = Math.floor(size.height);
    var texture = new cc.RenderTexture();
    texture.initWithSize(width, height, cc.gfx.RB_FMT_D24S8);
    texture.setPosition(cc.p(size.width / 2, size.height / 2));
    texture.begin();
    cc.director.getRunningScene().visit();
    texture.end();
    texture.saveToFile(fileName, cc.IMAGE_FORMAT_JPG);
}

原文地址:https://qilinzi.blog.csdn.net/article/details/89501956



如果这篇文章对你有所帮助,可以通过下边的“打赏”功能进行小额的打赏。

本网站部分内容来源于互联网,如有侵犯版权请来信告知,我们将立即处理。


来说两句吧