feat : add data parameter in Scene.switch #6876
Merged
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.
feat : add data parameter to Scene.switch
Thank you for creating an amazing framework. While developing with it, I've noticed a few areas that I think could benefit from some changes, and I'd like to make a suggestion.
Problem
When using the
switch
method in Phaser to change scenes, we use the start method if the scene is being loaded for the first time.And the start method allows us to pass data as a second parameter. However, the current implementation of the switch method only accepts a key, making it impossible to pass data.
This limitation forces us to use the following pattern:
Solution
Thus, I would like to propose adding a data parameter to the switch method.
However, this change would require modifications to the ScenePlugin pattern since a queueOp function in the scene currently has a maximum of three parameters.
The switch method already uses these for the event name, the current scene, and the scene to be started, leaving no room for passing data.
But the queueOp function's parameters are currently labeled keyA, keyB, etc., and in cases where only one key is needed, the third parameter is used to pass data. This could potentially confuse developers who want to contribute to the Phaser and use Phaser. ex) stop Method
Therefore, I propose adding a fourth parameter to optionally receive data.
In cases where only one key is needed, we could pass null as the third parameter and use the fourth parameter for data, similar to the bringToTop method.