【问题标题】:Phaser loading images dynamically after preloadPhaser 在预加载后动态加载图像
【发布时间】:2016-06-13 00:46:14
【问题描述】:

我正在使用 Phaser 开发一款游戏。这个游戏奖励玩家一个无法预装的物品。在 Ajax 调用之后,我希望加载图像,然后在移相器动画中显示它。有没有办法做到这一点?

流程:游戏正在玩 游戏完成并进行 Ajax 调用。 Ajax 响应使用哪个图像。 Phaser 加载图像并显示他们赢得了什么。

【问题讨论】:

    标签: javascript image preload phaser-framework


    【解决方案1】:

    您可以随时使用 Phaser 的加载器通过调用来加载图像

    game.load.image('referenceName', 'assets/pics/file.jpg');

    然后您可以设置一个类似的事件 http://phaser.io/examples/v2/loader/load-events

    game.load.onLoadComplete.add(aFunctionToCall, this);

    但最重要的是,在您完成所有设置后,请不要忘记实际告诉加载程序启动。

    game.load.start();

    【讨论】:

    • 这对我也有用。我调用了多个图像加载,它似乎要等到所有这些都完成后再调用 onLoadComplete。
    【解决方案2】:

    Phaser 3 中的延迟加载可以通过使用 Phaser.Loader.LoaderPlugin(scene) 来完成

    lazzyLoading:function(){
            var name = 'card-back';
            // texture needs to be loaded to create a placeholder card
            const card = this.add.image(WIDTH/2, HEIGHT/2, name);
    
            let loader = new Phaser.Loader.LoaderPlugin(this);
            // ask the LoaderPlugin to load the texture
            loader.image(name, 'assets/images/demon-large1.png');
    
            loader.once(Phaser.Loader.Events.COMPLETE, () => {
                // texture loaded so use instead of the placeholder
                card.setTexture(name)
            });
            loader.start();
        }
    

    【讨论】:

      猜你喜欢
      • 2016-12-12
      • 2014-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多