【问题标题】:Specify preload/create functions when instantiating Phaser.Game实例化 Phaser.Game 时指定预加载/创建函数
【发布时间】:2022-06-14 13:38:20
【问题描述】:

根据phaser.io/tutorials,可以为游戏实例设置一个初始的preload/create函数:

this.game = new Phaser.Game(800, 600, Phaser.AUTO, 'content', { preload: this.preload, create: this.create });

但是,我试图将这些构造函数参数作为对象传递:

SceneContainers.phaserGame = new Phaser.Game({
    width: ProjectSettings.resolution[0],
    height: ProjectSettings.resolution[1],
    type: Phaser.AUTO,
    parent: 'content',
    backgroundColor: ProjectSettings.backgroundColor,
    // 'preload: ...' and 'create: ...' do not exist here
    // Also, 'callbacks: ...' does not support 'preload: ...' and 'create: ...'
    // according to TypeScript completions.
});

preload/create 属于哪个属性?当我查看 API 文档时,我搜索 preload 并没有显示任何内容:Phaser.GamePhaser.Types.Core.GameConfig

【问题讨论】:

    标签: typescript phaser-framework


    【解决方案1】:

    简短的回答,它确实存在。它是scene 的属性。

    var config = {
        ...
        width: 800,
        height: 600,
        scene: { preload: preload, create: create },
        ...
    };
    

    虽然,该属性可以设置为其他数据类型。

    小更新:在这个教程部分,有几个很好的例子,关于如何使用这个属性https://phaser.io/examples/v3/category/scenes,我仍然参考这些例子,当我必须写相位器时应用程序/代码。

    【讨论】:

      猜你喜欢
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-19
      • 2014-03-19
      • 1970-01-01
      相关资源
      最近更新 更多