スプライト シートの特定のポイントから描画される値を含むステートメントをランダムに選択しようとしています。これは私が持っている現在のコードです。
this.asteroid = Math.floor(Math.random()*7+1);
switch(this.asteroid)
{
case 0:
this.srcX = 0;
this.srcY = 528;
this.width = 32;
this.height = 33;
break;
case 1:
this.srcX = 32;
this.srcY = 528;
this.width = 32;
this.height = 33;
break;
case 2:
this.srcX = 64;
this.srcY = 528;
this.width = 32;
this.height = 33;
break;
case 3:
this.srcX = 63;
this.srcY = 565;
this.width = 62;
this.height = 60;
break;
case 4:
this.srcX = 125;
this.srcY = 565;
this.width = 62;
this.height = 60;
break;
case 5:
this.srcX = 187;
this.srcY = 565;
this.width = 62;
this.height = 60;
break;
case 6:
this.srcX = 0;
this.srcY = 632;
this.width = 116;
this.height = 120;
break;
}
その後、選択した値を描画します。
ほとんどすべてを描画している問題ですが、同時に空白の画像だけを描画し、すべての X と Y の位置を確認しましたが、それらはすべて正しく、スプライト シートで一致しています。
以下は、スプライトを描画するために使用しているコードです。
this.drawX -= this.speed;
ctxEnemy.drawImage(imgSprite,
this.srcX+this.width,this.srcY,this.width,this.height,
this.drawX,this.drawY,this.width,this.height);
this.checkEscaped();