网上扒的截图功能代码,亲测可用,要用 模拟器测试模拟器测试模拟器测试

下面是完整功能:

captureAndShow () {
const winSize = cc.director.getWinSize();
const target = new cc.RenderTexture(winSize.width, winSize.height, 2);
this.target = target;
this.node._sgNode.addChild(target);
target.setPosition(cc.p(-2000, -2000));
var that=this;
var mySize=cc.view.getFrameSize();
cc.log(“mySize before—>”);
cc.log(“w–>”+mySize.width+" h–>"+mySize.height);
this.scheduleOnce(() => {
target.begin();
cc.director.getScene().getChildByName(“Canvas”)._sgNode.visit();
target.end();
var mySize=cc.view.getFrameSize();
cc.log(“mySize after—>”);
cc.log(“w–>”+mySize.width+" h–>"+mySize.height);
this.scheduleOnce(() => {
const image = target.newImage();
let imagePath=cc.path.join(jsb.fileUtils.getWritablePath(),“aaaaa”+(that.id++)+".jpg");
//保存图片到可写地址
image.saveToFile(imagePath, true)
//输出查看图片路径
console.log('imagePath: '+ imagePath);
//删除画布
that.target.removeFromParent(true);
//将图片显示在界面上
cc.loader.load(imagePath, function (err, tex) {
//将图片加入当前的界面
const winSize = cc.director.getWinSize();
var spf=new cc.SpriteFrame();
spf.initWithTexture(tex);
var node = new cc.Node();
var sp = node.addComponent(cc.Sprite);
sp.spriteFrame=spf;
node.parent = that.node;
node.setPosition(0,0);
node.setScale(.2,.2);
});
}, 0.2);
}, 0.2);
}

demo里有··········文档里也有

为什么用浏览器测试就挂了

saveToFile 这个方法是哪里来?

可能是 html5的 但肯定不是creator的 百度一下

可能是 html5的 但肯定不是creator的 百度一下

html5 那模拟器怎样能用泥?

额 我也是新手 你也百度一下 吧