我这里有一个小提琴。我要问的是太空船必须面向运动的方向,因为不这样做是没有意义的。无论如何,我认为我遇到的问题是找到一个角度,并在船以不同方式移动时让船旋转该角度。
function draw () { //Create and animates
var angle = Math.atan2(clickedChords.y - player.y, clickedChords.x - player.x);
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.fillStyle= 'white';
ctx.beginPath();
//Creates crossHair/nav marker
ctx.arc(clickedChords.x,clickedChords.y,3,0,360);
ctx.rect(clickedChords.x - 8,clickedChords.y - 1,16,2);
ctx.fill();
ctx.drawImage(ships.blueBeginers,player.x-15,player.y-15);
player.x += Math.cos(angle);
player.y += Math.sin(angle);
requestAnimationFrame(draw); //God
}
draw();
Run Code Online (Sandbox Code Playgroud)
我在翻译图像然后从图像中间旋转时遇到问题。这可能很简单,但我被卡住了。
感谢你们对我的帮助。