스프라이트 시트의 특정 지점에서 그려지는 값이 포함 된 명령문을 임의로 선택하려고합니다. 이것이 현재 코드입니다.자바 스크립트 html5 캔버스 랜덤 스위치 명령문 이미지
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();
예제 코드를 jsFiddle에 넣거나 적어도 그리기 작업을 수행하는 코드를 질문에 추가 할 수 있습니까? – BinaryTox1n
'this.drawX - = this.speed; ' \t'ctxEnemy.drawImage (imgSprite, this.srcX + this.width, this.srcY, this.width, this.height, this.drawX, this.drawY, this .width, this.height); ' 'this.checkEscaped(); ' 코드를 그립니다. – Nick