Skip to content

Commit 415c7fe

Browse files
committed
Added the sourceRect and maskRect parameters back into BitmapData.alphaMask as they were accidentally removed in 2.1 (thanks seejay92)
1 parent 7f23438 commit 415c7fe

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Version 2.1.2 - "Whitebridge" - in development
9393
### Updates
9494

9595
* TypeScript definitions fixes and updates (thanks @clark-stevenson @englercj)
96+
* Added the `sourceRect` and `maskRect` parameters back into `BitmapData.alphaMask` as they were accidentally removed in 2.1 (thanks seejay92)
9697

9798

9899

build/phaser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ declare module Phaser {
12481248

12491249
add(object: any): Phaser.BitmapData;
12501250
addToWorld(x?: number, y?: number, anchorX?: number, anchorY?: number, scaleX?: number, scaleY?: number): Phaser.Image;
1251-
alphaMask(source: any, mask: any): Phaser.BitmapData;
1251+
alphaMask(source: any, mask: any, sourceRect?: Phaser.Rectangle, maskRect?: Phaser.Rectangle): Phaser.BitmapData;
12521252
blendAdd(): Phaser.BitmapData;
12531253
blendColor(): Phaser.BitmapData;
12541254
blendColorBurn(): Phaser.BitmapData;

src/gameobjects/BitmapData.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,11 +1066,31 @@ Phaser.BitmapData.prototype = {
10661066
* @method Phaser.BitmapData#alphaMask
10671067
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapData|HTMLImage|HTMLCanvasElement|string} source - The source to copy from. If you give a string it will try and find the Image in the Game.Cache first. This is quite expensive so try to provide the image itself.
10681068
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapData|HTMLImage|HTMLCanvasElement|string} [mask] - The object to be used as the mask. If you give a string it will try and find the Image in the Game.Cache first. This is quite expensive so try to provide the image itself. If you don't provide a mask it will use this BitmapData as the mask.
1069+
* @param {Phaser.Rectangle} [sourceRect] - A Rectangle where x/y define the coordinates to draw the Source image to and width/height define the size.
1070+
* @param {Phaser.Rectangle} [maskRect] - A Rectangle where x/y define the coordinates to draw the Mask image to and width/height define the size.
10691071
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
10701072
*/
1071-
alphaMask: function (source, mask) {
1073+
alphaMask: function (source, mask, sourceRect, maskRect) {
10721074

1073-
return this.draw(mask).blendSourceAtop().draw(source).blendReset();
1075+
if (typeof maskRect === 'undefined' || maskRect === null)
1076+
{
1077+
this.draw(mask).blendSourceAtop();
1078+
}
1079+
else
1080+
{
1081+
this.draw(mask, maskRect.x, maskRect.y, maskRect.width, maskRect.height).blendSourceAtop();
1082+
}
1083+
1084+
if (typeof sourceRect === 'undefined' || sourceRect === null)
1085+
{
1086+
this.draw(source).blendReset();
1087+
}
1088+
else
1089+
{
1090+
this.draw(source, sourceRect.x, sourceRect.y, sourceRect.width, sourceRect.height).blendReset();
1091+
}
1092+
1093+
return this;
10741094

10751095
},
10761096

0 commit comments

Comments
 (0)