find的图像,但不是vj的Nodejs和Express

我有一个canvas,并在canvas上我想加载一个图像。

client.js

game.viewport = document.getElementById('viewport'); game.card1 = document.getElementById('card1'); //Adjust their size game.viewport.width = game.world.width; game.viewport.height = game.world.height; game.card1.width = game.cards.width; game.card1.height = game.cards.height; //Fetch the rendering contexts game.ctx = game.viewport.getContext('2d'); game.ctx2 = game.card1.getContext('2d'); 

game_core.js

  game_core.prototype.client_cards = function(game_instance) { this.instance = game_instance; var img = new Image(); img.src = '/images/Chainlinks/AddBurn.png'; this.ctx2.drawImage(img,10,20); this.ctx2.fillStyle = 'rgba(255,255,255,0.7)'; this.ctx2.fillText('Summoner: '+player1, 10 , 20); 

文本Summnor2:在canvas上是可分离的,但图像不被绘制。 如果我查看node.js的de cmd,他会find图像path。 所以我真的不知道哪里出了问题。

请帮助我

尝试这样的事情。 确保图像path正确。

 var self = this; var img = new Image(); img.src = './images/Chainlinks/AddBurn.png'; img.onload = function() { self.ctx2.drawImage(img,10,20); self.ctx2.fillStyle = 'rgba(255,255,255,0.7)'; self.ctx2.fillText('Summoner: '+player1, 10 , 20); };