2016-12-13 55 views
0

我一直在尝试使游戏开始时出现闪屏,并且它确实出现,但它会以太快的速度淡出。试图在函数内创建setTimeout,但它停止工作并完全破坏代码。JavaScript启动画面setTimeout问题。

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); 
} 

请帮忙。

预先感谢您。

+0

你可能需要更换'gameStart();''在用'的setTimeout(gameStart,5000)setup';'。 – Xufox

回答

0

移动的setTimeout功能gameStart外,即:

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

它应该在'setup()'中 – Barmar