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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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