3
I’m making a page that works as a GPS for a character in a given game. The content of the page is nothing more than a map with a marked path, and 240 images superimposing this map to "mark" the character’s location.
The 240 images take 40 minutes and 35 seconds to loop (go from the starting point to the end point, and return to the starting point).
With the help of Sergio on this other issue, I was able to adjust my code to change the images every 10 seconds, based on the current time.
Now the problem I’m facing is: my javascript has become absurdly large, with more than 40,000 lines, is leaving the page at approximately 1.8mb, and this can cause a slowdown for some users.
Following is logic for exchanging images:
function mudarYujia() {
var currentHora = new Date().getHours();
var currentMinuto = new Date().getMinutes();
var currentSegundo = new Date().getSeconds();
var img = document.getElementById("mapa_movimento");
var base = "http://triviapw.hiperportal.blog.br/elysium_old/images/moves/";
var prefixo = "floresta_yujia_v2-b-";
var extensao = ".png";
if (0<= currentHora && currentHora < 1){
if (2 <= currentMinuto && currentMinuto < 3){
if (45 <= currentSegundo && currentSegundo < 55){
img.src = base + prefixo + '1' + extensao;
}}}
if (0<= currentHora && currentHora < 1){
if (3 <= currentMinuto && currentMinuto < 4){
if (5 <= currentSegundo && currentSegundo < 15){
img.src = base + prefixo + '2' + extensao;
}}}
if (0<= currentHora && currentHora < 1){
if (3 <= currentMinuto && currentMinuto < 4){
if (15 <= currentSegundo && currentSegundo < 25){
img.src = base + prefixo + '3' + extensao;
}}}
if (0<= currentHora && currentHora < 1){
if (3 <= currentMinuto && currentMinuto < 4){
if (26 <= currentSegundo && currentSegundo < 36){
img.src = base + prefixo + '4' + extensao;
}}}
if (0<= currentHora && currentHora < 1){
if (3 <= currentMinuto && currentMinuto < 4){
if (36 <= currentSegundo && currentSegundo < 46){
img.src = base + prefixo + '5' + extensao;
}}}
...
return mudarYujia;
}
setInterval(mudarYujia(), 1000); // atualizar a cada 1 segundo
The function checks the current time, minute and second, to be able to tell which image should be displayed at this time. All images are numbered from 1 to 240 in this format "floresta_yujia_v2-b-1.png", "floresta_yujia_v2-b-2.png"...
The complete code can be seen here on jsfiddle
And the images superimposed on the map, which are exchanged, not just an object used to mark the location, and follow in this format, but in other positions
An important detail is that the character resumes the path (image "floresta_yujia_v2-b-1.png") every day at 00 hours, 2 minutes and 35 seconds.
I tried to find something on the Internet that could help me narrow it down, but I didn’t get any results.
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero