I need to draw a rotated rectangle in canvas by its center point, but I want to set a x
and y
to it. I'm actually moving the rectangle to $b.width / 2
and $b.height / 2
. I don't know how to do that.
This is my class code. Note: $b
is my rectange.
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 ++]);