Reactjs 雪碧有时不';移相器博弈中的t负载

Reactjs 雪碧有时不';移相器博弈中的t负载,reactjs,sprite,phaser-framework,Reactjs,Sprite,Phaser Framework,有时游戏开始时并不等待所有资产加载。这种情况最常见于空间站,它是最大的精灵,每秒3372x700像素。当游戏首次启动时,空间站未加载。但是,如果您离开游戏,然后在不刷新页面的情况下返回游戏,它将在第二次加载。我正在使用带有IonPhaser包装器的Phaser游戏引擎进行React 游戏在这里举行,因此您可以了解我的意思: 这是我的空间站精灵代码: import spaceStation from "../assets/space-station-sprite-sheet.png"; // o

有时游戏开始时并不等待所有资产加载。这种情况最常见于空间站,它是最大的精灵,每秒3372x700像素。当游戏首次启动时,
空间站
未加载。但是,如果您离开游戏,然后在不刷新页面的情况下返回游戏,它将在第二次加载。我正在使用带有IonPhaser包装器的Phaser游戏引擎进行React

游戏在这里举行,因此您可以了解我的意思:

这是我的
空间站
精灵代码:

import spaceStation from "../assets/space-station-sprite-sheet.png";

// other stuff...

preload: function() {

// other stuff...

    const spaceStationImg = new Image();
    spaceStationImg.onload = () => {
      this.textures.addSpriteSheet("spaceStation", spaceStationImg, {
        frameWidth: 3372,
        frameHeight: 700
      });
    };
    spaceStationImg.src = spaceStation;

// other stuff...

}

// other stuff...

create: function() {

// other stuff...

    const config = {
        key: "lights",
        frames: this.anims.generateFrameNumbers("spaceStation", {
          start: 0,
          end: 6
        }),
        frameRate: 3,
        repeat: -1
     };

     this.anims.create(config);

     this.spaceStation = this.impact.add
       .sprite(1686, 350, "spaceStation")
       .play("lights")
       .setDepth(1);

// other stuff...
}
我是否加载不正确


谢谢

使用react时,Phaser 3加载器应使用导入的精灵,而不是直接指向
preload()
函数中的相对路径

import spaceStation from "../assets/space-station-sprite-sheet.png";

// other stuff...

this.load.spritesheet(
            'spaceStation',
            spaceStation, // <-- not '../assets/space-station-sprite-sheet.png'
            {
              frameWidth:3372,
              frameHeight:700
            }
          );
从“./assets/space station sprite sheet.png”导入空间站;
//其他东西。。。
此.load.spritesheet(
“空间站”,
空间站//