fatboyarming Posted April 19, 2018 Share Posted April 19, 2018 I want like to create some animation ,The following is my script Step 1 go to step 2 after 5 seconds Step 2 go to step 3 after 3 seconds Step 3 back to step 1 after 3 seconds var stepOne = true; function create (){ // if (stepOne) { } <- alway true //Step 1 game.time.events.add(Phaser.Timer.SECOND * 5, function(){ stepOne = false; stepTwo = true; stepThree = false; console.log('go to step 2'); //Step 2 game.time.events.add(Phaser.Timer.SECOND * 3, function(){ stepOne = false; stepTwo = false; stepThree = true; console.log('go to step 3 '); //Step 3 game.time.events.add(Phaser.Timer.SECOND * 2, function(){ stepOne = true; stepTwo = false; stepThree = false; console.log('back to step 1 '); }, this); }, this); }, this); } Any idea how to loop it ??Thank you very much! I try to use "game.time.events.loop" ,but each time it goes to some step, it execute first step script, how to fix it ??? THX Link to comment Share on other sites More sharing options...
onlycape Posted April 19, 2018 Share Posted April 19, 2018 Hi @fatboyarming , This is a possible solution to your problem (code tested here: http://phaser.io/sandbox/tUzlOiss/play): var stepOne = true; function create() { game.time.events.loop(Phaser.Timer.SECOND*10,function(){ //Step 1 game.time.events.add(Phaser.Timer.SECOND * 5, function(){ stepOne = false; stepTwo = true; stepThree = false; console.log('go to step 2'); },this); //Step 2 game.time.events.add(Phaser.Timer.SECOND * 8, function(){ stepOne = false; stepTwo = false; stepThree = true; console.log('go to step 3 '); },this); //Step 3 game.time.events.add(Phaser.Timer.SECOND * 10, function(){ stepOne = true; stepTwo = false; stepThree = false; console.log('back to step 1 '); }, this); }, this); } Greetings. fatboyarming and samme 2 Link to comment Share on other sites More sharing options...
fatboyarming Posted April 20, 2018 Author Share Posted April 20, 2018 12 hours ago, onlycape said: Hi @fatboyarming , This is a possible solution to your problem (code tested here: http://phaser.io/sandbox/tUzlOiss/play): var stepOne = true; function create() { game.time.events.loop(Phaser.Timer.SECOND*10,function(){ //Step 1 game.time.events.add(Phaser.Timer.SECOND * 5, function(){ stepOne = false; stepTwo = true; stepThree = false; console.log('go to step 2'); },this); //Step 2 game.time.events.add(Phaser.Timer.SECOND * 8, function(){ stepOne = false; stepTwo = false; stepThree = true; console.log('go to step 3 '); },this); //Step 3 game.time.events.add(Phaser.Timer.SECOND * 10, function(){ stepOne = true; stepTwo = false; stepThree = false; console.log('back to step 1 '); }, this); }, this); } Greetings. Thanks @onlycape Thank you very much!!!!! Thanks for your help Have a nice day!!!!! I am happy Link to comment Share on other sites More sharing options...
Recommended Posts