Cocos Creator(2.x版本)屏幕截图保存分享)

本文介绍如何在Cocos Creator 2.1.1版本中实现屏幕截图并分享到微信小游戏。提供直接的代码实现。
摘要由CSDN通过智能技术生成

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
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值