Phaser 3 : Lighting between scenes, need help

Hello, i have multiple scene, one with my player and another one with all other basic functions, i want to use the lighting effects, i use it like this :

first scene :

create () {
this.lights.enable().setAmbientColor(’#999696’)
const bot = this.add.image(-100, 0, ‘bot’).setOrigin(0).setScale(0.7)
bot.setPipeline(‘Light2D’)
this.scene.launch(‘PlayerScene’)
}

the lights work, but in my scene “PlayerScene” i don’t see the light

PlayerScene :

this.playerLight = this.lights.addLight(180, 80, 200).setColor(0xffffff)
this.playerLight.x = this.player.x
this.playerLight.y = this.player.y

if i put all in the first scene, all work perfectly, but with two scene not, can you help me please ?

Hi,
Scenes are independant each others, they can communicate data, but a game object created in one scene can’t be displayed in another scene. Your light can’t work in the PlayerScene

I don’t know why you put the player in its own scene, but i don’t think it’s a good idea.

1 Like

Hello, thank you for your answer, I would like to separate my files as much as possible to avoid having files with too many lines.

For example, a file with the configuration of my player and the movements of the latter to avoid having to put everything back in each different scene,

is it possible ? If yes, how ?

Thank you :slight_smile:

Here’s how i do:
I use multiple scene, but only one GameScene, others scenes are for hud, map, menu, game over, …
I use multiple files, a Player Class file that handle the player.
For each enemies, a enemy class that extends an Enemy class file.
And i use multiple Service class files with static methods to not overload the scene file (LayerService, CameraService, ColliderService, …)
I don’t use multiple scene per level, i just have a LevelService that destroy everything, and load the next map, add layers, add enemies, …

1 Like

Thanks you,

Can you show me an example of the utilisation of your Player Class please ?

Something like this

export default class Player extends Phaser.GameObjects.Sprite {
  constructor(scene, x, y, config) {
    super(scene, x, y, config.key);
    this.setDepth(105);
    this.setPipeline('Light2D');
    this.scene.physics.world.enable(this);
    this.scene.add.existing(this);
    this.body.setSize(10, 25, true).setOffset(21, 10).setAllowGravity(false);
  }

  preUpdate(time, delta) {
    super.preUpdate(time, delta);
    // update logic here
  }
}
1 Like

Thanks a lot :slight_smile: