cocos creator (2.x版本)屏幕截图保存分享
cocos creator 屏幕截图 我用的是cocoscreator2.1.1版本
直接上代码
init() {
let node = new cc.Node();
node.parent = cc.director.getScene();
let camera = this.camera
// 设置你想要的截图内容的 cullingMask
// camera.cullingMask = 0xffffffff;
// 新建一个 RenderTexture,并且设置 camera 的 targetTexture 为新建的 RenderTexture,这样 camera 的内容将会渲染到新建的 RenderTexture 中。
let texture = new cc.RenderTexture();
this.texture = texture;
let gl = cc.game._renderContext;
// 如果截图内容中不包含 Mask 组件,可以不用传递第三个参数
texture.initWithSize(550, 550, gl.STENCIL_INDEX8);
camera.targetTexture = texture;
// 渲染一次摄像机,即更新一次内容到 RenderTexture 中
camera.render();
// 这样我们就能从 RenderTexture 中获取到数据了
let data = texture.readPixels();
},
createSprite() {
let width = this.texture.width;
let height = this.texture.height;
if (!thi