Jump to content

multiple states start


zidein
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...