Skip to content

Commit 111a4e1

Browse files
committed
Calling Rectangle.setSize() wouldn't change the underlying geometry of the Shape Game Object, causing any stroke to be incorrectly rendered after a size change.
1 parent edf074b commit 111a4e1

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

src/gameobjects/shape/rectangle/Rectangle.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ var RectangleRender = require('./RectangleRender');
1515
* treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling
1616
* it for input or physics. It provides a quick and easy way for you to render this shape in your
1717
* game without using a texture, while still taking advantage of being fully batched in WebGL.
18-
*
18+
*
1919
* This shape supports both fill and stroke colors.
20-
*
20+
*
2121
* You can change the size of the rectangle by changing the `width` and `height` properties.
2222
*
2323
* @class Rectangle
@@ -65,6 +65,37 @@ var Rectangle = new Class({
6565
this.updateData();
6666
},
6767

68+
/**
69+
* Sets the internal size of this Game Object, as used for frame or physics body creation.
70+
*
71+
* This will not change the size that the Game Object is rendered in-game.
72+
* For that you need to either set the scale of the Game Object (`setScale`) or call the
73+
* `setDisplaySize` method, which is the same thing as changing the scale but allows you
74+
* to do so by giving pixel values.
75+
*
76+
* If you have enabled this Game Object for input, changing the size will _not_ change the
77+
* size of the hit area. To do this you should adjust the `input.hitArea` object directly.
78+
*
79+
* @method Phaser.GameObjects.Rectangle#setSize
80+
* @since 3.13.0
81+
*
82+
* @param {number} width - The width of this Game Object.
83+
* @param {number} height - The height of this Game Object.
84+
*
85+
* @return {this} This Game Object instance.
86+
*/
87+
setSize: function (width, height)
88+
{
89+
this.width = width;
90+
this.height = height;
91+
92+
this.geom.setSize(width, height);
93+
94+
this.updateData();
95+
96+
return this;
97+
},
98+
6899
/**
69100
* Internal method that updates the data and path values.
70101
*

0 commit comments

Comments
 (0)