从循环中生成多个图像

Generate multiple images from loop

我尝试编写一个循环,从本地路径加载图像。为此,我尝试使用 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);

由于某些原因,图像没有出现。

我检查了什么:

加载图片时需要重新绘制图层:

playerIcon.onload = function() {
  playerLayer.batchDraw();
}