Custom loader / delay calling "create" on scene?

Hey all.

I’m trying to fetch some data from a server and only want to start creating the scene with the “create” function after it’s loaded. I was able to do it with “this.load.json()” but the problem is that I actually need to send a post request.

I currently have 2 solutions:

  • When my request is done, I set a custom attribute and in the update function I check if that attribute exists, if it does, then move to a new scene with the new data.

  • When my request is done, I set a custom attribute and in the create function I check if that attribute exists, if it doesn’t, then I set a timer to call the create function again and return.

I don’t like either solutions.

Is there a way to create a custom loader? Like “this.load.myCustomLoader” and then the “create()” function will only be called after this load is done?

If not, how is the correct way to fetch/post data from a server?

Thank you.

I had an await loader plugin, which await custom task in preload stage.
Here is a demo, wait 1 second in preload stage. (Document)

1 Like

Nice. This is exactly what I needed. Is it still working?

Yes, it is still working, you can try that demo to see the result.

Awesome! Thanks man, I will try it out today.

Also, I read your Phaser notes almost everyday. Thanks for the good work.

Hey @rexrainbow, how can I install your non-minified plugin on my project? I’d like to have it so I can better look at the source code and add it to my package.json and webpack.

I was trying to figure out which files to download from here https://github.com/rexrainbow/phaser3-rex-notes/tree/master/plugins but no clue.

Thank you.

I have a npm package, although it might not be the latest version of my plugins.
Entry of AwaitLoader plugin is here, and here is the body of AwaitLoader plugin.

1 Like