Hello guys,
I’m trying to send information from the main scene (freezing) to one of menus (when the person levels up to choose skill) and I’m using .emit and .on, but the information appears later (I run it 1x and nothing happens and on the second time the information is updated). I’ve already sent the .emit before and after using cena.launch. can you help me? I created a variable to not pass anything empty.
code main:
this.scene.launch('menuskill')
this.events.emit('descSkill1', this.listaDeSkills.razendepelo);
this.events.emit('descSkill2', this.listaDeSkills.morcego);
this.scene.pause()
this.mainScene = this.scene.get('menuskill');
this.mainScene.events.on('recebeMenu', (a) => {
this.levelText.setText(a)
});
Menu scene:
create(){
//this.img1 = this.add.image(400 - 100,300,'menuFundo').setInteractive()
//this.img2 = this.add.image(400 + 100,300,'menuFundo').setInteractive()
this.skill1 = ''
this.skill2 = ''
this.mainScene = this.scene.get('cena001');
this.mainScene.events.on('descSkill1', (a) => {
this.skill1 = a
console.log(this.skill1)
});
this.mainScene.events.on('descSkill2', (a) => {
this.skill2 = a
});
this.menu1 = this.add.image(400 - 105,300,'tester').setInteractive()
this.menu2 = this.add.image(400 + 105,300,'testeb').setInteractive()
this.menu1.on('pointerdown', function(){
this.events.emit('recebeMenu', this.skill1);
this.scene.resume('cena001')
this.scene.stop('menuskill')
}, this)
this.menu2.on('pointerdown', function(){
this.events.emit('recebeMenu', this.skill1);
this.scene.resume('cena001')
this.scene.stop('menuskill')
}, this)
}
Thanks.