Unexpected behavior of GameObject.Rectangle

I have a rectangle object created as follows:

 this.bar = this.add.rectangle(0, 256, 16, 256, 0x6666ff, 1)
 this.bar.setOrigin(0, 1)

I expect this to be a rectangle starting at y=256 and extending 256 pixels above. Therefore, when I change the height, I expect the rectangle to still be anchored at the bottom, and the top side to move down. In other words, I expect

this.bar.height = 128

to result in the rectangle top side to “drop” to y=128. Instead, what I observe is the rectangle being anchored a the top side, and the bottom side “moving up”. Is this expected?

Try

rect.setSize(width, height);

Reference

Or use instead

this.bar.displayHeight = 128;

setSize() does not change the result, the bar is shrinking from the wrong side. Assigning displayHeight works, but it’s not clear to me whether that’s the right solution. Isn’t displayHeight also affected by the game scaling policy?

It’s not. displayHeight is essentially height * scaleX.

filed confusing behavior when resizing Rectangle gameobject after setOrigin() · Issue #5527 · photonstorm/phaser · GitHub

But see Phaser.GameObjects.Shape#height.

Changing this value will not change the size that the Game Object is rendered in-game. For that you need to either set the scale of the Game Object ( setScale ) or use the displayHeight property.