Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Specify preload/create functions when instantiating Phaser.Game

According to phaser.io/tutorials, you can set a initial preload/create function for the game instance:

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

However, I’m trying to pass these constructor arguments as an object instead:

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.
});

To which property does belong preload/create? When I look at the API docs, I search for preload and nothing shows up: Phaser.Game and Phaser.Types.Core.GameConfig.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

the short answer is, is the property scene.

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

Althought, that property can also be set with other data types.

Minor Update: In this tutorial section, there are several nice examples, on how this property can be used https://phaser.io/examples/v3/category/scenes, I still consult these examples, when I have to write phaser apps/code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading