无论我做什么,我都无法让这段代码工作,您在 draw 方法中设置间隔的部分将在两秒内调用 Loop 方法 4 次,每次调用显示不同的图像。目前它什么都没有显示?问题不在于图像等,因为它可以很好地处理一张图像。在这呆了2天。。
function Explosion() //space weapon uses this
{
this.srcX = 0;
this.srcY = 1250;
this.drawX = 0;
this.drawY = 0;
this.width = 70;
this.height = 70;
this.currentFrame = 0;
this.totalFrames = 10;
this.hasHit = false;
this.frame = 0;
}
Explosion.prototype.draw = function()
{
if(this.hasHit == true && this.frame < 5)
{
var t=setTimeout(Explosion.Loop,500);
}
if(this.frame == 5)
{
clearTimeout(t);
this.hasHit = false;
this.frame = 0;
}
}
Explosion.prototype.Loop = function()
{
ctxExplosion.clearRect ( 0 , 0, canvasWidth , canvasHeight );
if(this.frame == 1)
{
ctxExplosion.drawImage(spriteImage,this.srcX,this.srcY,this.width,this.height,this.drawX,this.drawY,this.width,this.height);
frame++;
}
else if(this.frame == 2)
{
ctxExplosion.drawImage(spriteImage,this.srcX,(this.srcY + 77),this.width,this.height,this.drawX,this.drawY,this.width,this.height);
frame++;
}
else if(this.frame == 3)
{
ctxExplosion.drawImage(spriteImage,this.srcX,(this.srcY + 154),this.width,this.height,this.drawX,this.drawY,this.width,this.height);
frame++;
}
else if(this.frame == 4)
{
ctxExplosion.drawImage(spriteImage,this.srcX,(this.srcY + 231),this.width,this.height,this.drawX,this.drawY,this.width,this.height);
frame++;
}
}