在我可以使图像朝着它所面对的方向移动之前,我已经获得了效果。但是现在当我尝试时,图像会旋转,但不会朝正确的方向移动。如何使画布中的图像朝它所面对的方向移动?
我的代码:
ctx.save();
ctx.translate(bulletArray[i].x, bulletArray[i].y);
ctx.rotate(bulletArray[i].degree);
ctx.translate(-bulletArray[i].x, -bulletArray[i].y);
bulletArray[i].x++;
ctx.drawImage(bullet, bulletArray[i].x, bulletArray[i].y, 10, 10);
ctx.restore();
(这是在游戏循环中,所以它会重复)