转载自 https://blog.csdn.net/haibo19981/article/details/81251900
1.前言
截屏。
cocos creator没有截屏方法。论坛上提供的方法也不怎么好。
这里使用微信的接口实现截屏。
2.代码
var can = cc.game.canvas;
can.toTempFilePath({
// x: 0,
// y: 0,
// width: cc.winSize.width,
// height: cc.winSize.height,
destWidth: 750,
destHeight: 1334,
// fileType: "png",
// quality: 1.0,
success(res) {
console.log("截图成功", res)
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
console.log("收藏成功", res)
wx.hideLoading();
},
fail(res) {
console.log("收藏失败", res)
wx.hideLoading();
},
})
},
fail(res) {
console.log("截图失败", res)
wx.hideLoading();
},
})