Currently, I am working on a mini-game that requires some animations to be implemented in the form of frames per second. Here is my current approach:
var loadCount = 0;
var ticks = 15;
function loadingLoop() {
loadCount++;
}
switch (loadCount) {
case 1:
$("#img").attr("src", "src/images/cenario/img004.png");
break;
case 2:
$("#img").attr("src", "src/images/cenario/img005.png");
break;
case 3:
$("#img").attr("src", "src/images/cenario/img006.png");
break;
// etc.... //
}
setInterval(function(){
if (loadCount >= 6 && loadCount <= ticks){
loadingLoop();
if (loadCount === ticks) {
clearInterval();
}
console.log(loadCount);
}
}, 500);
I am interested in exploring more efficient ways to achieve the same goal. Any suggestions or recommendations would be greatly appreciated.