我试着做一个简单的塔防御游戏。我的坦克在沿路行驶。我怎样才能告诉他们在X/Y轴上停下来,旋转并移动到一个不同的方向?
function panzer(){
this.x = 0;
this.y = 230;
this.xSpeed = 5;
this.display = function(){ //function to display tank
playArea.context.drawImage(panzerImg,this.x,this.y,400,270);
}
this.move = function(){ //function to move
//while(this.x != 1800){ Commented concept to move while x(axis) != 1800
this.x += this.xSpeed;
if((this.x+20)<0) this.x = playArea.canvas.width;
// }
}
}发布于 2020-04-30 15:07:31
你可以让它像
if(this.x==POSITION && this.y==POSITION){
ROTATE
}在if()部分,这意味着当坦克的X和Y位置在你希望它停止和旋转的位置时,然后旋转。
你旋转的方式是改变坦克的X和Y速度。如果你想做更多,然后在不同的方向再拍一张坦克的图片,然后是drawImage。
https://stackoverflow.com/questions/61525956
复制相似问题