【发布时间】:2014-03-22 10:00:18
【问题描述】:
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。我还不确定为什么会出现问题。有谁知道为什么有时图像没有绘制到画布上?
感谢您发布...
【问题讨论】:
标签: html image canvas onload drawimage