1
I have been working with animation and studying and reading a lot I found this method with the best performance among others existing, both for use on the computer and for Smartphones, abusurdamente efficient.
My doubt is whether this correct call cancelAnimationFrame to the previous frame if you are delayed or not necessary to put this cancellation line and why?
Explaining the logic:
/* CRYO VARIABLE
Raf: int, old/current Raf id value running */
/* CRYO VARIABLE
time: float, stores the Domhighrestimestamp value that is timed with each run Raf, floating values can represent microseconds/miileseconds depending on the browser, this value must be used with the current time for scorpo comparisons and execution time */
/* Function: fc_loop_infinite_raf (Arg) Description: Creation: 20/1/2019 Updated: 3/3/2019
https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
requestAnimationFrame: function, method informs the browser that Voce wants to run an animation and prompts the browser to call a specified function to update an animation before the next repeat. The method receives a call return as an argument to be called before the repinture.
Arg: from "Function fc_loop_infinito_raf (Arg), and now a Domhighrestimestamp provided by Raf
https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp
logic and practice withdrawal of:
https://developer.mozilla.org/en-US/docs/Games/Anatomy */
;{
let
raf = 0,
tempo = 0,
fc_loop_infinito_raf = function (arg) {
// CONDICAO CANCELA OS FRAMES ANTIGOS
if (arg > tempo) {
console.log ('CANCELO RAF '+ raf);
// CANCELA O FRAME ANTERIOR CASO TENHA OCORRIDO ATRASO
window.cancelAnimationFrame (raf);
}
raf = window.requestAnimationFrame (fc_loop_infinito_raf);
tempo = (arg !== undefined ? arg : 0);
// FUNCAO DE ATUALIZACAO
// FUNCAO DESENHA
console.log ('EXECUTA RAF '+ raf +' - '+ tempo);
};
// INICIO CICLO DO RAF
fc_loop_infinito_raf ();
}
or so would be correct? (If so, why?)
;{
let
raf = 0,
tempo = 0,
fc_loop_infinito_raf = function (arg) {
raf = window.requestAnimationFrame (fc_loop_infinito_raf);
tempo = (arg !== undefined ? arg : 0);
// FUNCAO DE ATUALIZACAO
// FUNCAO DESENHA
console.log ('EXECUTA RAF '+ raf +' - '+ tempo);
};
// INICIO CICLO DO RAF
fc_loop_infinito_raf ();
}
There is this similar question in the English stack but no answer!
Right, maybe I got confused in the readings and with polyfill method, and I didn’t really see being used the function cancelAnimationFrame. Thank you!
– user78859