如何在 Phaser Framework 中截取 canvas 的屏幕截图?

How do I take a screenshot of canvas in Phaser Framework?

我正在使用 Phaser Framework 制作游戏。我尝试使用 todateurl 但它没有定义,我做错了什么?

var game = new Phaser.Game(1000, 700, Phaser.CANVAS, 'game');
game.state.add('boot', boots);
game.state.add('load', loads);  
game.state.start('boot');  
console.log(game);   // works
console.log(game.canvas);    // works
game.canvas.toDataURL();    //undefined

好的,你需要一个 link 当用户点击它时它会保存屏幕截图

var clickToSave= document.getElementById('linkeId');

function saveCanvas(link, filename) {
        link.href = game.canvas.toDataURL();
        link.download = filename;
};
clickToSave.onclick = function(){

var name = "name."+"png";

    saveCanvas(this, name);

};