dthrasher90 Posted March 8, 2017 Share Posted March 8, 2017 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.start(); tweenB.start(); tweenC.start(); tweenD.start() 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); game.state.start('HuddleState'); } else { console.log('incommplete pass'); } Link to comment Share on other sites More sharing options...
samme Posted March 8, 2017 Share Posted March 8, 2017 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 More sharing options...
dthrasher90 Posted March 8, 2017 Author Share Posted March 8, 2017 Which is the create callback? Link to comment Share on other sites More sharing options...
samme Posted March 8, 2017 Share Posted March 8, 2017 Usually it's the "create" function. Link to comment Share on other sites More sharing options...
Recommended Posts