Scale Polygon from the center point of polygon

let polygonData = [[539,364],[364,614],[714,614]];

let polygon1 = scene.add.polygon(0,0, polygonData, 0x0000ff);
polygon1.setScale(1.5);
polygon1.setOrigin(0.5);

let polygon2 = scene.add.polygon(0,0, polygonData, 0x00ff00);
polygon2.setScale(1);
polygon2.setOrigin(0.5);

Hi, I try to build a racing track with some polygon data like the following picture. However, it is not able to achieve gold with the above code. Any idea?

1 Like

I think you have found a bug. It doesn’t look like it sets the correct origin.

Maybe create a bug report.

From docs:

By default the x and y coordinates of this Shape refer to the center of it. However, depending on the coordinates of the points provided, the final shape may be rendered offset from its origin.

Yeah, but what does that help? If you create a polygon, set the origin to 0.5 and scale, it’s wrong. I guess we need some barycentric origin or something.

After Google, I found the above solution which calculates the scaled polygon first.