Jump to content

[Solved]How to loop time.events ??


fatboyarming
 Share

Recommended Posts

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

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.

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

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