Skip to content

Commit 8b1e736

Browse files
committed
BitmapData.rect provides a quick way to draw a Rectangle to a BitmapData.
1 parent d6183c0 commit 8b1e736

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/gameobjects/BitmapData.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,28 @@ Phaser.BitmapData.prototype = {
854854

855855
},
856856

857+
/**
858+
* Draws a filled Rectangle to the BitmapData at the given x, y coordinates and width / height in size.
859+
*
860+
* @method Phaser.BitmapData#rect
861+
* @param {number} x - The x coordinate of the top-left of the Rectangle.
862+
* @param {number} y - The y coordinate of the top-left of the Rectangle.
863+
* @param {number} width - The width of the Rectangle.
864+
* @param {number} height - The height of the Rectangle.
865+
* @param {string} [fillStyle] - If set the context fillStyle will be set to this value before the rect is drawn.
866+
*/
867+
rect: function (x, y, width, height, fillStyle) {
868+
869+
if (typeof fillStyle !== 'undefined')
870+
{
871+
this.context.fillStyle = fillStyle;
872+
}
873+
874+
this.context.fillRect(x, y, width, height);
875+
this.context.fill();
876+
877+
},
878+
857879
/**
858880
* Draws a filled Circle to the BitmapData at the given x, y coordinates and radius in size.
859881
*

0 commit comments

Comments
 (0)