How to create multi-file scenes?

I have a Phaser scene, but the code for it is getting very long. Is there any way to split one Phaser scene into multiple Javascript files.

If not already, i suggest you to install node.js and use the phaser 3 template.

Then, you can import js files on your scene.

Or if you don’t want a template, you can create a js file myFunction.js with:

export function functionName(scene, x, y){
  scene.add.image(x, y, 'textureName')

And in your scene file, at the top:

import functionName from './yourScriptFolder/myFunction.js';

// and use it like:
functionName(this, 100, 100);

More info here:


Thanks, this will help a lot! Thank you!