简体   繁体   中英

Javascript splash screen setTimeout issue.

I've been trying to make a splash screen appear when the game starts, and it does appear, but it fades out way too fast. Tried to create setTimeout within the function, but it stops working and breaks the code completely.

var introimg;
var intro = true;
function gameStart() {
    ctx.clearRect(0,0,window.innerWidth, window.innerHeight);
    ctx.drawImage(introimg, 0,0,window.innerWidth, window.innerHeight);
//setTimeout(gameStart, 5000);

}

function setup(){
    introimg = new Image();
    introimg.src = 'ICE/data/splash.png';


  document.addEventListener("touchstart", onTouchStart);
  document.addEventListener("touchmove", onTouchMove);
  document.addEventListener("touchend", onTouchEnd);


  gameStart();
  draw();
}


function draw(){
  ctx.fillStyle = "rgba(0,0,0,0.1)";
  ctx.fillRect(0,0,window.innerWidth,window.innerHeight);

  for(var i = 0;i<ressources.length;i++){
    ressources[i].display();
  }

  requestAnimationFrame(draw);
}

Please help.

Thank you in advance.

Move setTimeout outside the function gameStart, iE:

function gameStart() {}
setTimeout(gameStart, 5000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM