Update Scene.js to clarify that scene properties are undefined in constructor #7039
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR
Describe the changes below:
When one is extending a scene, one might expect to be able to do something like the following (based on current docs):
The reason for this is understandable once you dive into the source code, which uses a custom class implementation instead of default ES6 classes/extend, although most users will be using the default classes in their code. Based on my understanding of this code, the reason for properties like
registry
not being available in the constructor is because the Scene class relies on theSceneManager.add()
to actually fill these properties, once the Scene has already been instantiated.However, if you're just a dev consuming this API, that isn't clear in the current documentation. To figure out why the above works relies on navigating the Phaser source code, understanding the custom class/inheritance implementation and then looking at
SceneManager
which as mentioned in its own docs should usually not be interacted with directly at all.Furthermore, the current docs might muddle the matter because they mention property unavailability in reference to the Scene Injection Map, which might cause a developer to try to figure out what that is, when that has nothing to do with this constructor issue.
All in all this is a minor doc addendum, but hopefully one that seems worthy of accepting, if only to save the next poor sap from getting very derailed by this 😅 (and questioning their basic understanding of how classes work in javascript or what the scene injection map is before realizing what was actually going on here 😵).
Thanks! :D