Jump to content

Switching States


Recommended Posts

Is there a way to  have phaser run mulitple tweens and switch states once the last one is completed?  How can I have phaser evaluate this?

var button = this.game.add.button(game.world.centerX, 500, 'button', function(){
                  alert("button pressed");

                  var tweenA = game.add.tween(wr1).to({x: '-200'  }, 2000);
                  var tweenB = game.add.tween(wr2).to({  y: '+200'  }, 2000);
                  var tweenC = game.add.tween(wr3).to({ x: '-200 '}, 2000);
                  var tweenD = game.add.tween(wr4).to({ y: '-200'}, 2000);


  tweenA.onComplete.add(updateMoves, this);
                    function updateMoves(){
                    var d20 = Math.floor((Math.random() * 20) + 1);

                    if(d20> 2){
                      console.log("ball caught by wr3");
                      game.state.add('HuddleState', HuddleState);

                    } else {
                      console.log('incommplete pass');



Link to comment
Share on other sites

In this case the tweens have equal durations so you can use onComplete.add on any one of them.

I would move

game.state.add('HuddleState', HuddleState);

into the create callback though, it probably doesn't need to be added more than once.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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