rotate 命令将 rect 平移到另一个位置处理

我在处理过程中将矩形旋转了 35。这是我的代码。


pushMatrix();

rotate(35);

stroke(74, 73, 74);

fill(156, 153, 153);

rect(cannon1PositionX,cannon1PositionY,25,60,50);

noStroke();

fill(173, 168, 173);

rect(cannon1PositionX + 3,cannon1PositionY + 4,20,50,50);

popMatrix();

但是,如果我将旋转更改为 40,则矩形将旋转并平移到另一个位置。如何解决这个问题?


交互式爱情
浏览 102回答 1
1回答

一只甜甜圈

你的问题是,当你第一次使用时,rotate()你是在参考整个画布旋转,所以当你使用时canon1PositionX,cannon1PositionY根据你当前面对画布的角度,位置会发生变化。您需要做的是:pushMatrix();// Go to the cannon positiontranslate(cannon1PositionX, cannon1PositionY);// Rotate to the right anglerotate(35);// Draw the cannon at the current position and with the right anglerect(0, 0, 25, 60, 50);// Draw the second cannon next to the current onerect(3, 4, 20, 50, 50);popMatrix();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript