captureScreen:function(endCaptureCB,successCB,captureNode){
let node = new cc.Node();
node.parent = cc.director.getScene();
node.width = cc.view.getVisibleSize().width;
node.height = cc.view.getVisibleSize().height;
node.x = cc.view.getVisibleSize().width / 2;
node.y = cc.view.getVisibleSize().height / 2;
let camera = node.addComponent(cc.Camera);
// 设置你想要的截图内容的 cullingMask
camera.cullingMask = 0xffffffff;
// 新建一个 RenderTexture,并且设置 camera 的 targetTexture 为新建的 RenderTexture,这样 camera 的内容将会渲染到新建的 RenderTexture 中。
let texture = new cc.RenderTexture();
let gl = cc.game._renderContext;
texture.initWithSize(cc.visibleRect.width, cc.visibleRect.height, gl.STENCIL_INDEX8);
camera.targetTexture = texture;
// 渲染一次摄像机,即更新一次内容到 RenderTexture 中
camera.render();
// 这样我们就能从 RenderTexture 中获取到数据了
let data = texture.readPixels();
let width = texture.width;
let height = texture.height;
let picData = new Uint8Array(width * height * 4);
let rowBytes = width * 4;
for (let row = 0; row < height; row++) {
let srow = height - 1 - row;
let start = srow * width * 4;
let reStart = row * width * 4;
// save the piexls data
for (let i = 0; i < rowBytes; i++) {
picData[reStart + i] = data[start + i];
}
}
endCaptureCB && endCaptureCB();
var fileName = "share.png";
let fullPath = jsb.fileUtils.getWritablePath() + fileName;
if (jsb.fileUtils.isFileExist(fullPath)) {
jsb.fileUtils.removeFile(fullPath);
}
let success = jsb.saveImageData(picData, width, height, fullPath);
if (success) {
cc.log("twl 截屏成功-->",fullPath,width,height);
successCB && successCB(fullPath);
}
else {
cc.error("save image data failed!");
}
},