zidein Posted April 29, 2018 Share Posted April 29, 2018 Hello, how can i start multiple states at the same time together? I want to use something like that _.each(components, (component, index) => { this.promises.push(new Promise((resolve) => { // in component class, i add some state new COMPONENTS[component.name](this.game, resolve, component.props); })); }); Promise.all(this.promises).then((results) => { console.log('Components ' + _.size(results) + ' has been loaded'); _.each(results, (componentName, index) => { this.game.state.start(componentName); }); this.destroy(); }); I like that structure more, is it possible ? i know that update method'll start in the both states and may be it's bad, but i want to make game with this structure. And also if it is possible, how can i stop update method in some states? if you want to see my component it is here: COMPONENTS.Move = class { constructor(game, resolve, props) { this.game = game; this.props = props; this.resolve = resolve; this.canMove = true; this.componentName = 'Move'; this.game.state.add(this.componentName, this); this.resolve(this.componentName); } preload() { // this.game.load.image('tiles', this.props.image); } create() { // this.resolve(this.componentName); } update() { let cursors = this.game.input.keyboard.createCursorKeys(); if (cursors.up.isDown) { this.game.camera.y -= 40; } else if (cursors.down.isDown) { this.game.camera.y += 40; } if (cursors.left.isDown) { this.game.camera.x -= 40; } else if (cursors.right.isDown) { this.game.camera.x += 40; } } }; And may be my english is bad, sorry, im from Russia Link to comment Share on other sites More sharing options...
onlycape Posted May 3, 2018 Share Posted May 3, 2018 Hi @zidein, For this case maybe Phaser 3 adapts better to what you want, since it is designed to run several states at same time if necessary. https://labs.phaser.io/view.html?src=src\scenes\multiple scenes from classes.js Regards. zidein 1 Link to comment Share on other sites More sharing options...
Recommended Posts