gpt4 book ai didi

node.js - 找到图像但不可见 Nodejs 和 Express

转载 作者:太空宇宙 更新时间:2023-11-03 22:17:31 24 4
gpt4 key购买 nike

我有一个 Canvas ,我想在 Canvas 中加载图像。

客户端.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,他会找到图像路径。所以我真的不知道哪里出了问题。

最佳答案

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

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

关于node.js - 找到图像但不可见 Nodejs 和 Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20974533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com