2015-01-09 50 views
0

我正在使用Phaser Framework製作遊戲。我嘗試使用todateurl,但沒有定義,我做錯了什麼?如何在Phaser Framework中截取畫布?

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 
+0

你可以提供一個[小提琴](http://jsfiddle.net)證明了問題? – user2570380 2015-01-10 01:42:47

回答

0

確定你需要它的鏈接,當用戶點擊它保存截圖

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); 

};