Documentation for the scene object in GameConfig

The documentation for the scene object in GameConfig is extremely thin:

A scene or scenes to add to the game. If several are given, the first is started; the remainder are started only if they have { active: true }.

And it doesn’t match my expectations coming from the tutorial:

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

It looks like the object does have some expected structure.

In the documentation for Phaser.Time.Clock.now it is even suggested, that the update function has a parameter!

Is there any thorough documentation for the scene object and the parameters for its functions?

this might be helpful

1 Like

It’s Phaser.Scenes.Settings.Config plus init(), preload(), create(), update(), plus extend.

@theNeedle: That was an very interesting read, thanks for the link. However, it did not answer all my questions. My first guess was that the object in question is indeed a scene object, but Phaser.Scene does not define a preload() nor a create() method. But then in the first code snippet the class extending Phaser.Scene does define a create() function. I’m confused, how that function is ever going to be called.

@samme: Could you please expand on your answer a little bit? My first question would be, why is this nowhere documented? Or am I missing some basic understanding and this should go without further explanation?

The init() function you mentioning I’m seeing for the first time. I also would like to know, what exactly is the difference between the preload() and the create() function? They’re both called before the game runs, right?

And I’m pretty sure, the update() function has parameters. Maybe the same as the update() function documented in Phaser.Scene? Now I’m wondering, maybe the other functions have some parameters as well?

And what about extend?

See ‘What happens when you create a scene’ in Dev Log #119. That explains the scene methods.

init(), preload(), and create() are called when the scene is started. If the loader has items queued after preload() completes, then it starts automatically, and create() is called only after the loading is complete.

The next release will include these methods in the Phaser.Scene docs. They’re identical to the methods with the same names in a scene config object.

Any properties on extend are copied onto the scene after it’s created.

2 Likes

this rex-note (especially the flowchart) will help in understanding how scene methods are called. Dev log #119 that samme shared is absolute gem. It cleared out some of my doubts too.

1 Like