function rendercanvas()
{
if(!window.isDirty && !gameover)
{
context.clearRect(0,0,window.innerWidth,1000);
backofcardred = new Image();
backofcardred.addEventListener('load', drawDealerStack);
backofcardred.src = "graphics/backofcardred.jpg";// + '?' + (new Date()).getTime();
backofcardblue = new Image();
backofcardblue.addEventListener('load', drawClientStack);
backofcardblue.src = "graphics/backofcardblue.jpg";// + '?' + (new Date()).getTime();
context.beginPath();
context.rect(100, 195, 100, 146);
context.fillStyle = 'blue';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'black';
context.stroke();
context.beginPath();
context.rect(100, 343, 100, 146);
context.fillStyle = 'red';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'black';
context.stroke();
context.beginPath();
context.fillStyle = 'black';
context.strokeStyle = 'black';
context.font = 'italic 30pt Calibri';
var message = "Client Score:"+clientTally+" Dealer Score:"+dealerTally;
context.fillText(message, 220,100);
if(currentWinner!="")
{
}
}
if(window.isDirty && !gameover)
{
context.clearRect(0,0,window.innerWidth,1000);
context.beginPath();
context.fillStyle = 'black';
context.strokeStyle = 'black';
context.font = 'italic 30pt Calibri';
var message = "Client Score:"+clientTally+" Dealer Score:"+dealerTally;
context.fillText(message, 220,100);
context.fillStyle = 'black';
context.strokeStyle = 'black';
context.font = 'italic 10pt Calibri';
backofcardred = new Image();
backofcardred.addEventListener('load', drawDealerStack);
backofcardred.src = "graphics/backofcardred.jpg";// + '?' + (new Date()).getTime();
backofcardblue = new Image();
backofcardblue.addEventListener('load', drawClientStack);
backofcardblue.src = "graphics/backofcardblue.jpg";// + '?' + (new Date()).getTime();
if(clientwarareastack.cards[0] != null)
{
context.beginPath();
context.rect(100,343,100,146);
context.fillStyle = 'white';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'white';
context.stroke();
context.beginPath();
suitecharacter(clientwarareastack.cards[0]);
var message = clientwarareastack.cards[0].rank + " " + suitUChar;
context.fillText(message, 100+10, 343+25);
}
else
{
context.beginPath();
context.rect(100, 343, 100, 146);
context.fillStyle = 'red';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'black';
context.stroke();
}
if(dealerwarareastack.cards[0] != null)
{
context.beginPath();
context.rect(100,195,100,146);
context.fillStyle = 'white';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'white';
context.stroke();
suitecharacter(dealerwarareastack.cards[0]);
var message = dealerwarareastack.cards[0].rank + " " + suitUChar;
context.fillText(message, 100+10, 195+25);
}
else
{
context.beginPath();
context.rect(100, 195, 100, 146);
context.fillStyle = 'blue';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'white';
context.stroke();
}
}
if(gameover)
{
context.clearRect(0,0,window.innerWidth,1000);
context.fillText("GAME OVER. REFRESH THE PAGE TO START OVER.FINAL WINNER:"+finalwinner, 100+10, 195+25);
}
}
function drawDealerStack() {
context.beginPath();
context.drawImage(backofcardblue, 100, 50);
context.stroke();
}
function drawClientStack() {
context.beginPath();
context.drawImage(backofcardred, 100, window.originYclientstack);
context.stroke();
}
backofcardred
和backofcardblue
有时不会渲染到画布。大部分时间我看到backofcardred
和backofcardblue
所以问题是间歇性的。取消注释// + '?' + (new Date()).getTime();
只会使问题变得更糟。是否有任何事情可以确保每次加载图像?我不反对jQuery。我不确定为什么这个问题正在发生。有谁知道为什么图像有时不被绘制到画布上?图像加载有时不起作用
感谢您张贴...
有这么好的帖子很难选择只有一个作为我的回答,但是这篇文章有很多好的指针,我认为它会被标记为答案。感谢您的发表。我喜欢使用onload函数 – Giuseppe