I am working on school project in JavaScript. (Tower Defence).
I am trying to rotate a tank at X / Y Coordinates. But I am having trouble with rotate function (90°).
function preloadAssets(){
this.Menu = new Image();
this.Menu.src = "C:/Users/Filip/Desktop/JS/background/menu.png";
this.background = new Image();
this.background.src="../Background/background.png";
this.tigerImg = new Image();
this.tigerImg.src = "C:/Users/Filip/Desktop/JS/background/tiger_e.png";
}
function tiger(){
this.x = 0;
this.y = 230;
this.angle = 0;
this.moveangle = 5;
this.display = function(){ //function to display the tank
playArea.context.drawImage(tigerImg,this.x,this.y,500,250);
}
this.move = function(){ //function to move the tank
if (this.x + tx > 1900){
tx = 0;
}
if (this.x + tx >= 1890){
this.y -= ty;
}
this.x += tx;
}
}
function redraw(){
playArea.clearCanvas();
tiger.move();
drawBackground();
}
I was thinking of something like adding this into the move function:
this.angle += this.moveangle;
rotate(this.angle);
if(this.angle == 90){
this.moveangle = 0;
}