cocos creator 手机截屏分享二维码 完整写法。小子虽然不才但也讨厌很多人 直接复制别人的博客粘贴到自己上面还不补全。说多了就是泪啊!不说多了上代码。加班写出来的没有优化谅解哈。
1.这里是手机截屏功能
// Learn cc.Class:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// // ATTRIBUTES:
// default: null, // The default value will be used only when the component attaching
// // to a node for the first time
// type: cc.SpriteFrame, // optional, default is typeof default
// serializable: true, // optional, default is true
// },
// bar: {
// get () {
// return this._bar;
// },
// set (value) {
// this._bar = value;
// }
// },
_canvas: null,
targetNode: cc.Node,
camera: cc.Camera
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
this.init();
},
init() {
let texture = new cc.RenderTexture();
texture.initWithSize(this.targetNode.width, this.targetNode.height, cc.gfx.RB_FMT_S8);
this.camera = this.node.addComponent(cc.Camera);
this.camera.targetTexture = texture;
this.texture = texture;
},
start() {
if (CC_JSB && cc.sys.isNative) {
this.camera.enabled = true;