MTiger Posted March 30, 2020 Share Posted March 30, 2020 In my game the player will create a character (TODO), then start the game. The game starts by placing one tile on the board Right now I just have a GameController which is a phaser Scene In the Game Controller I want to have instances to the board and the UI Menu so that I can communicate with the other scenes throughout the game The issue that I am currently having (and I think that it is because of JS single threaded nature) is that I need to wait for the Board's create method is complete before I can start calling the other methods, but scene.run does not start until Game.create is done (and I tried Game.preload) So the question is there a way to wait / detect until scene.run is finished? I know that there are certain events that a scene triggers but can I hook into another objects events like on('Board:transitioncomplete',()=>) Is there a cleaner way to structure the order of these events? create() { this.board = this.scene.get('Board'); this.board = this.scene.get('UI'); this.scene.run('Board'); this.startGame(); } startGame() { this.board.createRoom(0, 0, 'N'); // this.UI.renderMessage({ message: 'Welcome to the dungeon', parameters: 'Param1' }, (param) => console.log(`Hello from Game with ${param}`)); } Link to comment Share on other sites More sharing options...
MTiger Posted March 31, 2020 Author Share Posted March 31, 2020 I solve my problem in the short term by rapping the statements in a setImmediate statement so they get placed in the event loop and the method can complete setImmediate(() => this.startGame()); Link to comment Share on other sites More sharing options...
Recommended Posts