What is the difference between using For Loop and Schedule?

I wish to understand the difference between For Loop and schedule. I’m using Typescript to create a spin button and I want the button to spin unlimited times, during the process I found out this issue. Can the combination of scheduleOnce and unschedule used to replace For Loop?

What I understood are

unschedule: unschedule a custom callback function

scheduleOnce: schedule a callback function only once, with a delay of 0 or larger

Below are my code: What I tried to do is unschedule an A event until certain time, and then trigger B event but only schedule once

export default class SpinController extends cc.Component {    

  private static SPIN_SPEED: number = 6;

  spineTouchStart() {
      this._speedUp();
  }

  private _speedUp(multiplier = SpinController.SPIN_SPEED) { 
      this.unschedule(this.slowDownUpdate);  
      this._trackLoop.timeScale = multiplier / 2.0; 
      this.scheduleOnce(() => {
          this._trackLoop.timeScale = multiplier;
      }, 0.1)
  }
}

What do you mean by For Loop? Can you provide a link to the relevant documentation? JavaScript has about 5 variations of the for statement and perhaps you are referring to a TypeScript thing. What do you mean by schedule? I don’t see schedule in the JavaScript documentation; is it a TypeScript thing?

If you want to create a smooth animation you should look at window.requestAnimationFrame().

Yes, I’m asking in Typescript language

Can this used in Cocos Creator? Because right now I’m doing game development using Typescript

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.