我尝试编写一个循环,从本地路径加载图像。为此,我尝试使用Konva:
const playerLayer = new Konva.Layer();
var playerAmount = 1;
while (playerAmount < 6) {
var playerIcon = new Image();
var playerInstance = new Konva.Image({
x: 660,
y: 140,
image: playerIcon,
width: 32,
height: 32
});
playerIcon.src = "media/heroes/hero1.png";
playerLayer.add(playerInstance);
playerAmount++;
}
stage.add(playerLayer);
出于某种原因,图片不会出现。
我检查了什么:
答案 0 :(得分:2)
您需要在加载图片时重新绘制图层:
playerIcon.onload = function() {
playerLayer.batchDraw();
}