Set duration time in progress bar

Greetings to all

Can you tell me how to make a progress bar, which has a duration of about 15 seconds, for example?

Currently I use this code, but the duration time is not very accurate and I have to use a timer to validate how long it lasts and according to the level I need to change this value and I would like it to be with a value that I can put in a variable.

tiempo(dt) {

    tiempoRestante = this.barraProgreso.progress;
        
        if (tiempoRestante > 0) {
            tiempoRestante -= 0.0012;
            this.barraProgreso.progress = tiempoRestante;
        }
},

If I use a time interval the bar lasts the exact time, but the change is seen to give sudden changes.

Use this.schedule

1 Like

@Andres_IC . Thanks for the answer, could you give me an example of how you should use it please?

let timer=(dt)=>{

        time+=dt; 

        if(time>=15)
        { 
            //do something
            this.unschedule(timer);
        } 

    };

    this.schedule(timer,0,cc.macro.REPEAT_FOREVER);

@Andres_IC Thank you very much for the information

1 Like