# Problem with Phaser 4 rectangles.

**URL:** <https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652>\
**Category:** Phaser 3\
**Created:** [September 4, 2026, 8:11pm UTC](https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652 "2026-09-04T20:11:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![m9gbr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/m9gbr/32/9409_2.png) [@m9gbr](https://phaser.discourse.group/u/m9gbr)\
**Post date:** [September 4, 2026, 8:11pm UTC](https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652/1 "2026-09-04T20:11:00Z")

</div>

So yeah I updated my project from Phaser 3 to 4 because of the preFX problem on mobile and I’ve stumbled on yet another problem.

If I create a rectangle and set its origin to (1, 0), it turns into a rectangle… yes from square to rectangle.

It was working well in Phaser 3 and I don’t know what to do. Please help…

---

<div class="post-metadata">

**Author:** ![johnSSG](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/johnssg/32/8138_2.png) [@johnSSG](https://phaser.discourse.group/u/johnSSG)\
**Post date:** [September 4, 2026, 11:42pm UTC](https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652/2 "2026-09-04T23:42:16Z")

</div>

Can you post a simple example of this issue for me? I haven’t seen something like this in Phaser 4.

---

<div class="post-metadata">

**Author:** ![m9gbr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/m9gbr/32/9409_2.png) [@m9gbr](https://phaser.discourse.group/u/m9gbr)\
**Post date:** [September 5, 2026, 8:06am UTC](https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652/3 "2026-09-05T08:06:25Z")

</div>

No problem

this.testSqr = this.add.rectangle(300, 300, 100, 100, 0x0, 0)  
this.testSqr.setStrokeStyle(5, 0xff0000)  
this.testSqr.setOrigin(1, 0)

Just found out it the problem only exists for stroke-styling

---

<div class="post-metadata">

**Author:** ![m9gbr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/m9gbr/32/9409_2.png) [@m9gbr](https://phaser.discourse.group/u/m9gbr)\
**Post date:** [September 5, 2026, 2:42pm UTC](https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652/4 "2026-09-05T14:42:21Z")

</div>

Also just found out now that making the rectangle rounded by calling rect.setRounded(radius) fixes this problem.

Also I created a rectangular polygon and set the origin to (1, 0) and it also turned into a triangle.

this.poly = this.add.polygon(300, 300, [0, 0, 100, 0, 100, 100, 0, 100], 0x0, 0).setOrigin(1, 0).setStrokeStyle(5, 0x0)

---

<div class="post-metadata">

**Author:** ![johnSSG](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/johnssg/32/8138_2.png) [@johnSSG](https://phaser.discourse.group/u/johnSSG)\
**Post date:** [September 5, 2026, 6:09pm UTC](https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652/5 "2026-09-05T18:09:31Z")

</div>

Can you send your game config?

---

<div class="post-metadata">

**Author:** ![m9gbr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/m9gbr/32/9409_2.png) [@m9gbr](https://phaser.discourse.group/u/m9gbr)\
**Post date:** [September 7, 2026, 8:40am UTC](https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652/6 "2026-09-07T08:40:11Z")

</div>

// main.js code

import { Game } from “phaser”  
import TestScene from “./test.js”

class BoardGame extends Game {

constructor() {

super({

canvas: document.querySelector(“#game-canvas”),

type: WEBGL,

width: 1200,

height: 675,

transparent:true,

scale: {

mode: Scale.FIT,

autoCenter: Scale.CENTER\_BOTH

},

scene: [TestScene]

})

}

}

new BoardGame

// test.js code

import { Scene } from “phaser”

export default TestScene extends Scene {  
constructor() {super(“scene”)}

```javascript
create() {
    this.testSqr = this.add.rectangle(300, 300, 100, 100, 0x0, 0)
    this.testSqr.setStrokeStyle(5, 0xff0000)
    this.testSqr.setOrigin(1, 0)
}

```

}

---

<div class="post-metadata">

**Author:** ![johnSSG](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/johnssg/32/8138_2.png) [@johnSSG](https://phaser.discourse.group/u/johnSSG)\
**Post date:** [September 7, 2026, 11:33pm UTC](https://phaser.discourse.group/t/problem-with-phaser-4-rectangles/15652/7 "2026-09-07T23:33:07Z")

</div>

Thanks, it looks like that is a bug, perhaps related to this:

> <https://github.com/phaserjs/phaser/issues/7361>
>
> \*\*Version:\*\* Phaser 4.2.1; the code is unchanged on \`master\`. Not present in 3.x…, whose \`StrokePathWebGL\` has no duplicate-point check. WebGL renderer only (the Canvas renderer strokes the full path).
> 
> \*\*Repro:\*\*
> 
> \`\`\`js
> // A 6px diamond, centred by the default origin. Its stroke reaches three of the four
> // corners and cuts across the fill; the fill itself is whole.
> this.add.polygon(400, 300, \[3, 0, 6, 3, 3, 6, 0, 3\], 0x7d9c55)
> .setStrokeStyle(1, 0x000000)
> .setScale(20);
> \`\`\`
> 
> Any centred diamond does it, whatever its size or the order of its corners.
> 
> \*\*Cause:\*\* in \`src/gameobjects/shape/StrokePathWebGL.js\`, the loop that builds \`pointPath\` skips a point it takes for a repeat of the previous one:
> 
> \`\`\`js
> var x = path\[i\] - dx;
> var y = path\[i + 1\] - dy;
> if (i \> 0)
> {
> if (x === path\[i - 2\] && y === path\[i - 1\])
> {
> // Duplicate point, skip it
> continue;
> }
> }
> \`\`\`
> 
> \`x\` and \`y\` have the display origin (\`dx\`, \`dy\`) subtracted; \`path\[i - 2\]\` and \`path\[i - 1\]\` have not. So the test fires whenever a vertex lies exactly \`(dx, dy)\` past the previous one, which is true of one edge of every centred diamond, and it never catches a genuinely repeated vertex unless \`dx\` and \`dy\` are both zero.
> 
> \*\*Fix:\*\* compare against the previous \*shifted\* point, e.g. the last entry pushed to \`pointPath\`, or against \`path\[i - 2\] - dx\` and \`path\[i - 1\] - dy\`.
> 
> \*\*Workaround:\*\* a Rectangle turned 45° draws the same diamond with a closed stroke; its path never meets the condition.

This will draw a square though:

```javascript
const graphics = this.add.graphics();

graphics.lineStyle(5, 0xff0000, 1);
graphics.strokeRect(200, 300, 100, 100);

```

This also fixes it, but may not work for you:

`this.testSqr.setOrigin(0.5);`
