我这里有一张画布。我正在尝试在此上绘制一个 svg,但它根本不起作用。如果我使用png文件,它可以正常工作。
drawPlayer() {
this.xCord = this.colNum * this.width;
this.yCord = this.rowNum * this.height;
let rat = new Image();
let player = this;
rat.onload = function() {player.ctx.drawImage(rat, player.xCord, player.yCord,
player.width, player.height);}
rat.src = "Lik-Rong-IT.svg";
}
我也试过这种方式-
<img src="Lik-Rong-IT.svg" id="rat" style="display: none"/>
drawPlayer() {
this.xCord = this.colNum * this.width;
this.yCord = this.rowNum * this.height;
let rat = document.querySelector("#rat");
let player = this;
rat.onload = function() {player.ctx.drawImage(rat, player.xCord, player.yCord,
player.width, player.height);}
}
但这也不起作用(即使是 png!)。我已经查找了我可以在我的代码中找到的任何错误,但没有运气。请帮我找出问题!
链接到项目 - https://codesandbox.io/s/maze-p2pyo
千万里不及你
相关分类