Skip to content

Commit f34b567

Browse files
committed
BitmapData.copy, and by extension any method that uses it, including BitmapData.draw, drawGroup and drawFull, now all support drawing RenderTexture objects. These can either be passed directly, or be the textures of Sprites, such as from a call to generateTexture.
1 parent 9483267 commit f34b567

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
339339

340340
### New Features
341341

342-
*
342+
* BitmapData.copy, and by extension any method that uses it, including BitmapData.draw, drawGroup and drawFull, now all support drawing RenderTexture objects. These can either be passed directly, or be the textures of Sprites, such as from a call to generateTexture.
343343
*
344344
*
345345

src/gameobjects/BitmapData.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ Phaser.BitmapData.prototype = {
12051205
* You can use the more friendly methods like `copyRect` and `draw` to avoid having to remember them all.
12061206
*
12071207
* @method Phaser.BitmapData#copy
1208-
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapData|Image|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.
1208+
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapData|Phaser.RenderTexture|Image|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.
12091209
* @param {number} [x=0] - The x coordinate representing the top-left of the region to copy from the source image.
12101210
* @param {number} [y=0] - The y coordinate representing the top-left of the region to copy from the source image.
12111211
* @param {number} [width] - The width of the region to copy from the source image. If not specified it will use the full source image width.
@@ -1228,6 +1228,11 @@ Phaser.BitmapData.prototype = {
12281228

12291229
if (source === undefined || source === null) { source = this; }
12301230

1231+
if (source instanceof Phaser.RenderTexture || source instanceof PIXI.RenderTexture)
1232+
{
1233+
source = source.getCanvas();
1234+
}
1235+
12311236
this._image = source;
12321237

12331238
if (source instanceof Phaser.Sprite || source instanceof Phaser.Image || source instanceof Phaser.Text || source instanceof PIXI.Sprite)
@@ -1239,7 +1244,15 @@ Phaser.BitmapData.prototype = {
12391244
this._anchor.set(source.anchor.x, source.anchor.y);
12401245
this._rotate = source.rotation;
12411246
this._alpha.current = source.alpha;
1242-
this._image = source.texture.baseTexture.source;
1247+
1248+
if (source.texture instanceof Phaser.RenderTexture || source.texture instanceof PIXI.RenderTexture)
1249+
{
1250+
this._image = source.texture.getCanvas();
1251+
}
1252+
else
1253+
{
1254+
this._image = source.texture.baseTexture.source;
1255+
}
12431256

12441257
if (tx === undefined || tx === null) { tx = source.x; }
12451258
if (ty === undefined || ty === null) { ty = source.y; }
@@ -1398,7 +1411,7 @@ Phaser.BitmapData.prototype = {
13981411
* Copies the area defined by the Rectangle parameter from the source image to this BitmapData at the given location.
13991412
*
14001413
* @method Phaser.BitmapData#copyRect
1401-
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapData|Image|string} source - The Image to copy from. If you give a string it will try and find the Image in the Game.Cache.
1414+
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapData|Phaser.RenderTexture|Image|string} source - The Image to copy from. If you give a string it will try and find the Image in the Game.Cache.
14021415
* @param {Phaser.Rectangle} area - The Rectangle region to copy from the source image.
14031416
* @param {number} x - The destination x coordinate to copy the image to.
14041417
* @param {number} y - The destination y coordinate to copy the image to.
@@ -1419,7 +1432,7 @@ Phaser.BitmapData.prototype = {
14191432
* When drawing it will take into account the Sprites rotation, scale and alpha values.
14201433
*
14211434
* @method Phaser.BitmapData#draw
1422-
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text} source - The Sprite, Image or Text object to draw onto this BitmapData.
1435+
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.RenderTexture} source - The Sprite, Image or Text object to draw onto this BitmapData.
14231436
* @param {number} [x=0] - The x coordinate to translate to before drawing. If not specified it will default to `source.x`.
14241437
* @param {number} [y=0] - The y coordinate to translate to before drawing. If not specified it will default to `source.y`.
14251438
* @param {number} [width] - The new width of the Sprite being copied. If not specified it will default to `source.width`.

0 commit comments

Comments
 (0)