Write Phaser 3 scenes without `this`

3 Likes

@samme thanks for sharing, and of course it works fine.
but what problem are you trying to solve?

this is a very useful language construct.
By changing it to a global, you lose core strengths of Phaser’s architecture:
the independence of scene instances, and the facile inheritance of scene classes.

You can no longer, for example, craft a basic scene:for your game (JumpScene)
and then extend the scene to create your levels. StreetJumpScene, CaveJumpScene, etc

I am surely missing something. Please explain.

2 Likes

I think the reason for posting it was that this is really confusing to learn as a beginner. When I started Phaser at least (I had only done javascript for 3 months as a hobby) I had no idea what this was referring to and I just assumed it was some magical keyword that made everything work. It took me at least a few weeks to finally google what it was :grin:.

3 Likes

@Dov indeed, I should have explained. I was trying to think of a technique for people who are stuck on the matter of using this in scenes correctly and who would rather access the scene like a “normal variable”.

1 Like