截屏我弄过,兼容Web和JSB,以下是代码(TypeScript版本,去掉类型就是js):
/**
* 捕捉屏幕作为一个PNG文件保存在路径filename
*/
public static captureScreenshot(filename: string): void {
if (this.isWebPlayer) {
var canvas: HTMLCanvasElement = document.getElementById("gameCanvas");
var base64: string = canvas.toDataURL("image/png");
var href: string = base64.replace(/^data:image[^;]*/, "data:image/octet-stream");
var aLink: HTMLAnchorElement = document.createElement('a');
aLink['download'] = filename;
aLink.href = href;
var evt = document.createEvent("HTMLEvents");
evt.initEvent("click", false, false);
aLink.dispatchEvent(evt);
}
else {
var size: cc.Size = cc.view.getVisibleSize();
var texture: cc.RenderTexture = new cc.RenderTexture(size.width, size.height, cc.IMAGE_FORMAT_PNG);
texture.begin();
cc.director.getRunningScene().visit();
texture.end();
texture.saveToFile(filename, cc.IMAGE_FORMAT_PNG);
}
}
↧
请问Creator有没有截屏的方法
↧