Yeah, the anchorPoint is only for adjusting how a renderable anchors to an entity. The shapes have their own API.
Effectively, a shape needs its vertices defined relative to the center point. And me.Rect puts the center point at the upper-left corner. (This makes me sad.) The bad news is that this will require a major redesign. The good news is that there's a workaround if you need the shape's physical center changed :
- Convert the rect into a polygon (if it is not already a polygon) with toPolygon()
- Get the poly's points array
- Adjust the points so they are relative to the expected center
- Call setShape() with the new points array
It's ugly. :( But it will get you unblocked.
You might also have to adjust the anchorPoint and entity position after this transformation step. Once it's done, the shape can be freely rotated around its center.
If you do not need to change the physical center, then you can use the standard translation steps surrounding the rotation, which sets the virtual center for rotation:
shape.translate(shape.width / 2, shape.height / 2);
shape.rotate(Math.PI / 4);
shape.translate(-shape.width / 2, -shape.height / 2);