【发布时间】:2016-07-30 19:00:59
【问题描述】:
我需要在画布中按其中心点绘制一个旋转的矩形,但我想为其设置x 和y。我实际上将矩形移动到$b.width / 2 和$b.height / 2。我不知道该怎么做。
这是我的课程代码。注意:$b 是我的矩形。
do {
switch($b.t) {
case 0: { // draw rectangle
context.fillStyle = $b.tint;
if($b.rotate) {
context.save();
context.translate($b.width, $b.height);
context.rotate(($b.rotate * Math.PI) / 180);
context.fillRect(-$b.width / 2, -$b.height / 2, $b.width, $b.height);
context.restore();
}else{
context.fillRect($b.width / 2, $b.height / 2, $b.width, $b.height);
}
break;
}
}
} while($b = queue[$i ++]);
【问题讨论】: