0

在我可以使图像朝着它所面对的方向移动之前,我已经获得了效果。但是现在当我尝试时,图像会旋转,但不会朝正确的方向移动。如何使画布中的图像朝它所面对的方向移动?

我的代码:

    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();

(这是在游戏循环中,所以它会重复)

4

2 回答 2

0

好的。它不旋转的原因是因为旋转点需要是屏幕的中心而不是子弹。这将使子弹正确移动,而不仅仅是旋转。

于 2020-09-15T18:36:56.700 回答
-1

如果您不想旋转,请不要使用

ctx.rotate(bulletArray[i].degree);

在你的代码中

于 2020-09-15T17:25:56.293 回答