From 7ff8d51f985f41d65b891e703d2c61abaf304dd1 Mon Sep 17 00:00:00 2001 From: samme Date: Wed, 24 Oct 2018 12:14:44 -0700 Subject: [PATCH 1/3] Docs for input and physics events --- src/gameobjects/GameObject.js | 8 +- src/input/InputPlugin.js | 183 ++++++++++++++++++++++++++++++++++ src/physics/arcade/Body.js | 6 +- src/physics/arcade/World.js | 59 ++++++++--- 4 files changed, 239 insertions(+), 17 deletions(-) diff --git a/src/gameobjects/GameObject.js b/src/gameobjects/GameObject.js index 9a209c0fb..0d0424982 100644 --- a/src/gameobjects/GameObject.js +++ b/src/gameobjects/GameObject.js @@ -515,8 +515,9 @@ var GameObject = new Class({ * Game Object Pool instead of destroying it, as destroyed objects cannot be resurrected. * * @method Phaser.GameObjects.GameObject#destroy + * @fires Phaser.GameObjects.GameObject#destroyEvent * @since 3.0.0 - * + * * @param {boolean} [fromScene=false] - Is this Game Object being destroyed as the result of a Scene shutdown? */ destroy: function (fromScene) @@ -591,3 +592,8 @@ var GameObject = new Class({ GameObject.RENDER_MASK = 15; module.exports = GameObject; + +/** + * The Game Object will be destroyed. + * @event Phaser.GameObjects.GameObject#destroyEvent + */ diff --git a/src/input/InputPlugin.js b/src/input/InputPlugin.js index 401ff82ef..c7552c86b 100644 --- a/src/input/InputPlugin.js +++ b/src/input/InputPlugin.js @@ -748,6 +748,9 @@ var InputPlugin = new Class({ * * @method Phaser.Input.InputPlugin#processDownEvents * @private + * @fires Phaser.GameObjects.GameObject#pointerdownEvent + * @fires Phaser.Input.InputPlugin#gameobjectdownEvent + * @fires Phaser.Input.InputPlugin#pointerdownEvent * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The Pointer being tested. @@ -809,6 +812,20 @@ var InputPlugin = new Class({ * * @method Phaser.Input.InputPlugin#processDragEvents * @private + * @fires Phaser.GameObjects.GameObject#dragendEvent + * @fires Phaser.GameObjects.GameObject#dragenterEvent + * @fires Phaser.GameObjects.GameObject#dragEvent + * @fires Phaser.GameObjects.GameObject#dragleaveEvent + * @fires Phaser.GameObjects.GameObject#dragoverEvent + * @fires Phaser.GameObjects.GameObject#dragstartEvent + * @fires Phaser.GameObjects.GameObject#dropEvent + * @fires Phaser.Input.InputPlugin#dragendEvent + * @fires Phaser.Input.InputPlugin#dragenterEvent + * @fires Phaser.Input.InputPlugin#dragEvent + * @fires Phaser.Input.InputPlugin#dragleaveEvent + * @fires Phaser.Input.InputPlugin#dragoverEvent + * @fires Phaser.Input.InputPlugin#dragstartEvent + * @fires Phaser.Input.InputPlugin#dropEvent * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The Pointer to check against the Game Objects. @@ -1077,6 +1094,8 @@ var InputPlugin = new Class({ * * @method Phaser.Input.InputPlugin#processMoveEvents * @private + * @fires Phaser.GameObjects.GameObject#pointermoveEvent + * @fires Phaser.Input.InputPlugin#gameobjectmoveEvent * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The pointer to check for events against. @@ -1142,6 +1161,10 @@ var InputPlugin = new Class({ * * @method Phaser.Input.InputPlugin#processOverOutEvents * @private + * @fires Phaser.GameObjects.GameObject#pointeroutEvent + * @fires Phaser.GameObjects.GameObject#pointeroverEvent + * @fires Phaser.Input.InputPlugin#gameobjectoutEvent + * @fires Phaser.Input.InputPlugin#gameobjectoverEvent * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The pointer to check for events against. @@ -1312,6 +1335,8 @@ var InputPlugin = new Class({ * * @method Phaser.Input.InputPlugin#processUpEvents * @private + * @fires Phaser.GameObjects.GameObject#pointerupEvent + * @fires Phaser.Input.InputPlugin#gameobjectupEvent * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The pointer to check for events against. @@ -2493,3 +2518,161 @@ var InputPlugin = new Class({ PluginCache.register('InputPlugin', InputPlugin, 'input'); module.exports = InputPlugin; + +/** + * A Pointer stopped dragging the Game Object. + * @event Phaser.GameObjects.GameObject#dragendEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer that was dragging this Game Object. + * @param {number} dragX - The x coordinate where the Pointer is dragging the object, in world space. + * @param {number} dragY - The y coordinate where the Pointer is dragging the object, in world space. + * @param {boolean} dropped - True if the object was dropped within its drop target. (In that case, 'drop' was emitted before this.) + * + * The Game Object entered its drop target, while being dragged. + * @event Phaser.GameObjects.GameObject#dragenterEvent + * @param {Phaser.Input.Pointer} pointer - The pointer dragging this Game Object. + * @param {Phaser.GameObjects.GameObject} target - The Game Object's drop target. + * + * The Game Object is being dragged by a Pointer. + * @event Phaser.GameObjects.GameObject#dragEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object. + * @param {number} dragX - The x coordinate where the Pointer is dragging the object, in world space. + * @param {number} dragY - The y coordinate where the Pointer is dragging the object, in world space. + * + * The Game Object left its drop target, while being dragged. + * @event Phaser.GameObjects.GameObject#dragleaveEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object. + * @param {Phaser.GameObjects.GameObject} target - The Game Object's drop target. + * + * The Game Object is within its drop target, while being dragged. + * @event Phaser.GameObjects.GameObject#dragoverEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object. + * @param {Phaser.GameObjects.GameObject} target - The Game Object's drop target. + * + * A Pointer began dragging the Game Object. + * @event Phaser.GameObjects.GameObject#dragstartEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object. + * @param {number} dragX - The x coordinate where the Pointer is dragging the object, in world space. + * @param {number} dragY - The y coordinate where the Pointer is dragging the object, in world space. + * + * The Game Object was released on its drop target, after being dragged. + * @event Phaser.GameObjects.GameObject#dropEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object. + * @param {Phaser.GameObjects.GameObject} target - The Game Object's drop target. + * + * A Pointer was pressed on the Game Object. + * @event Phaser.GameObjects.GameObject#pointerdownEvent + * @param {Phaser.Input.Pointer} + * @param {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. + * @param {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. + * @param {object} eventContainer + * + * A Pointer moved while over the Game Object. + * @event Phaser.GameObjects.GameObject#pointermoveEvent + * @param {Phaser.Input.Pointer} + * @param {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. + * @param {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. + * @param {object} eventContainer + * + * A Pointer left the Game Object, after being over it. + * @event Phaser.GameObjects.GameObject#pointeroutEvent + * @param {Phaser.Input.Pointer} - The Pointer. + * @param {object} eventContainer + * + * A Pointer entered the Game Object, after being outside it. + * @event Phaser.GameObjects.GameObject#pointeroverEvent + * @param {Phaser.Input.Pointer} - The Pointer. + * @param {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. + * @param {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. + * @param {object} eventContainer + * + * A Pointer was released while over the Game Object, after being pressed on the Game Object. + * @event Phaser.GameObjects.GameObject#pointerupEvent + * @param {Phaser.Input.Pointer} - The Pointer. + * @param {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. + * @param {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. + * @param {object} eventContainer + */ + +/** + * A Game Object was released, after being dragged. + * @event Phaser.Input.InputPlugin#dragendEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {boolean} dropped - True if the Game Object was dropped onto its drop target. + * + * A dragged Game Object entered it drop target. + * @event Phaser.Input.InputPlugin#dragenterEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {Phaser.GameObjects.GameObject} target - The drop target. + * + * A Game Object is being dragged by a Pointer. + * @event Phaser.Input.InputPlugin#dragEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {number} dragX - The x coordinate where the Pointer is dragging the object, in world space. + * @param {number} dragY - The y coordinate where the Pointer is dragging the object, in world space. + * + * A dragged Game Object left its drop target. + * @event Phaser.Input.InputPlugin#dragleaveEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {?Phaser.GameObjects.GameObject} target - The drop target. + * + * A dragged Game Object is within its drop target. + * @event Phaser.Input.InputPlugin#dragoverEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {?Phaser.GameObjects.GameObject} target - The drop target. + * + * A Pointer started dragging a Game Object. + * @event Phaser.Input.InputPlugin#dragstartEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * + * A Game Object was dropped within its drop target. + * @event Phaser.Input.InputPlugin#dropEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {?Phaser.GameObjects.GameObject} target - The drop target. + * + * A Pointer was pressed while over a Game Object. + * @event Phaser.Input.InputPlugin#gameobjectdownEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {object} eventContainer + * + * A Pointer moved while over a Game Object. + * @event Phaser.Input.InputPlugin#gameobjectmoveEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {object} eventContainer + * + * A Pointer moved off of a Game Object, after being over it. + * @event Phaser.Input.InputPlugin#gameobjectoutEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {object} eventContainer + * + * A Pointer moved onto a Game Object, after being off it. + * @event Phaser.Input.InputPlugin#gameobjectoverEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {object} eventContainer + * + * A Pointer was released while over a Game Object, after being pressed on the Game Object. + * @event Phaser.Input.InputPlugin#gameobjectupEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object. + * @param {object} eventContainer + * + * A Pointer was pressed down. + * @event Phaser.Input.InputPlugin#pointerdownEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject[]} currentlyOver - All the Game Objects currently under the Pointer. + * + * A Pointer was released, after being pressed down. + * @event Phaser.Input.InputPlugin#pointerupEvent + * @param {Phaser.Input.Pointer} pointer - The Pointer. + * @param {Phaser.GameObjects.GameObject[]} currentlyOver - All the Game Objects currently under the Pointer. + */ diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index 5c2cf6545..52586f9f6 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -401,7 +401,7 @@ var Body = new Class({ * @type {boolean} * @default false * @since 3.0.0 - * @see Phaser.Physics.Arcade.World#event:worldbounds + * @see Phaser.Physics.Arcade.World#worldboundsEvent */ this.onWorldBounds = false; @@ -412,7 +412,7 @@ var Body = new Class({ * @type {boolean} * @default false * @since 3.0.0 - * @see Phaser.Physics.Arcade.World#event:collide + * @see Phaser.Physics.Arcade.World#collideEvent */ this.onCollide = false; @@ -423,7 +423,7 @@ var Body = new Class({ * @type {boolean} * @default false * @since 3.0.0 - * @see Phaser.Physics.Arcade.World#event:overlap + * @see Phaser.Physics.Arcade.World#overlapEvent */ this.onOverlap = false; diff --git a/src/physics/arcade/World.js b/src/physics/arcade/World.js index 51d73049a..5b0a2da84 100644 --- a/src/physics/arcade/World.js +++ b/src/physics/arcade/World.js @@ -32,36 +32,47 @@ var Vector2 = require('../../math/Vector2'); var Wrap = require('../../math/Wrap'); /** - * @event Phaser.Physics.Arcade.World#pause + * The physics simulation paused. + * @event Phaser.Physics.Arcade.World#pauseEvent */ /** - * @event Phaser.Physics.Arcade.World#resume + * The physics simulation resumed (from a paused state). + * @event Phaser.Physics.Arcade.World#resumeEvent */ /** - * @event Phaser.Physics.Arcade.World#collide + * Two Game Objects collided. + * This event is emitted only if at least one body has `onCollide` enabled. + * @event Phaser.Physics.Arcade.World#collideEvent * @param {Phaser.GameObjects.GameObject} gameObject1 * @param {Phaser.GameObjects.GameObject} gameObject2 * @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body1 * @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body2 + * @see Phaser.Physics.Arcade.Body#onCollide */ /** - * @event Phaser.Physics.Arcade.World#overlap + * Two Game Objects overlapped. + * This event is emitted only if at least one body has `onOverlap` enabled. + * @event Phaser.Physics.Arcade.World#overlapEvent * @param {Phaser.GameObjects.GameObject} gameObject1 * @param {Phaser.GameObjects.GameObject} gameObject2 * @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body1 * @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body2 + * @see Phaser.Physics.Arcade.Body#onOverlap */ /** - * @event Phaser.Physics.Arcade.World#worldbounds + * A Body contacted the world boundary. + * This event is emitted only if the body has `onWorldBounds` enabled. + * @event Phaser.Physics.Arcade.World#worldboundsEvent * @param {Phaser.Physics.Arcade.Body} body * @param {boolean} up * @param {boolean} down * @param {boolean} left * @param {boolean} right + * @see Phaser.Physics.Arcade.Body#onWorldBounds */ /** @@ -853,7 +864,7 @@ var World = new Class({ * checks. * * @method Phaser.Physics.Arcade.World#pause - * @fires Phaser.Physics.Arcade.World#pause + * @fires Phaser.Physics.Arcade.World#pauseEvent * @since 3.0.0 * * @return {Phaser.Physics.Arcade.World} This World object. @@ -871,7 +882,7 @@ var World = new Class({ * Resumes the simulation, if paused. * * @method Phaser.Physics.Arcade.World#resume - * @fires Phaser.Physics.Arcade.World#resume + * @fires Phaser.Physics.Arcade.World#resumeEvent * @since 3.0.0 * * @return {Phaser.Physics.Arcade.World} This World object. @@ -1361,8 +1372,8 @@ var World = new Class({ * Separates two Bodies. * * @method Phaser.Physics.Arcade.World#separate - * @fires Phaser.Physics.Arcade.World#collide - * @fires Phaser.Physics.Arcade.World#overlap + * @fires Phaser.Physics.Arcade.World#collideEvent + * @fires Phaser.Physics.Arcade.World#overlapEvent * @since 3.0.0 * * @param {Phaser.Physics.Arcade.Body} body1 - The first Body to be separated. @@ -1476,8 +1487,8 @@ var World = new Class({ * Separates two Bodies, when both are circular. * * @method Phaser.Physics.Arcade.World#separateCircle - * @fires Phaser.Physics.Arcade.World#collide - * @fires Phaser.Physics.Arcade.World#overlap + * @fires Phaser.Physics.Arcade.World#collideEvent + * @fires Phaser.Physics.Arcade.World#overlapEvent * @since 3.0.0 * * @param {Phaser.Physics.Arcade.Body} body1 - The first Body to be separated. @@ -2132,8 +2143,10 @@ var World = new Class({ * Please use Phaser.Physics.Arcade.World#collide instead. * * @method Phaser.Physics.Arcade.World#collideSpriteVsTilemapLayer - * @fires Phaser.Physics.Arcade.World#collide - * @fires Phaser.Physics.Arcade.World#overlap + * @fires Phaser.GameObjects.GameObject#collideEvent + * @fires Phaser.GameObjects.GameObject#overlapEvent + * @fires Phaser.Physics.Arcade.World#collideEvent + * @fires Phaser.Physics.Arcade.World#overlapEvent * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} sprite - The first object to check for collision. @@ -2363,3 +2376,23 @@ var World = new Class({ }); module.exports = World; + +/** + * A physics-enabled Game Object collided with a Tile. + * This event is emitted only if the Game Object's body has `onCollide` enabled. + * @event Phaser.GameObjects.GameObject#collideEvent + * @param {Phaser.GameObjects.GameObject} gameObject + * @param {Phaser.Tilemaps.Tile} tile + * @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body + * @see Phaser.Physics.Arcade.Body#onCollide + */ + +/** + * A physics-enabled Game Object overlapped with a Tile. + * This event is emitted only if the Game Object's body has `onOverlap` enabled. + * @event Phaser.GameObjects.GameObject#overlapEvent + * @param {Phaser.GameObjects.GameObject} gameObject + * @param {Phaser.Tilemaps.Tile} tile + * @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body + * @see Phaser.Physics.Arcade.Body#onOverlap + */ From 7d1f990ad3a70ace6c1ca36998a57150beb88845 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sat, 10 Nov 2018 04:22:13 +0000 Subject: [PATCH 2/3] Added ERASE blend mode. --- src/renderer/BlendModes.js | 9 ++++++++- src/renderer/webgl/WebGLRenderer.js | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/renderer/BlendModes.js b/src/renderer/BlendModes.js index 4f14be84b..b295d08b5 100644 --- a/src/renderer/BlendModes.js +++ b/src/renderer/BlendModes.js @@ -140,6 +140,13 @@ module.exports = { * * @name Phaser.BlendModes.LUMINOSITY */ - LUMINOSITY: 16 + LUMINOSITY: 16, + + /** + * Alpha erase blend mode. + * + * @name Phaser.BlendModes.ERASE + */ + ERASE: 17 }; diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index cc6354be7..c514c0fdb 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -505,7 +505,7 @@ var WebGLRenderer = new Class({ // Set it back into the Game, so developers can access it from there too this.game.context = gl; - for (var i = 0; i <= 16; i++) + for (var i = 0; i <= 17; i++) { this.blendModes.push({ func: [ gl.ONE, gl.ONE_MINUS_SRC_ALPHA ], equation: gl.FUNC_ADD }); } @@ -513,6 +513,7 @@ var WebGLRenderer = new Class({ this.blendModes[1].func = [ gl.ONE, gl.DST_ALPHA ]; this.blendModes[2].func = [ gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA ]; this.blendModes[3].func = [ gl.ONE, gl.ONE_MINUS_SRC_COLOR ]; + this.blendModes[17].func = [ gl.ZERO, gl.ONE_MINUS_SRC_ALPHA ]; this.glFormats[0] = gl.BYTE; this.glFormats[1] = gl.SHORT; @@ -1092,7 +1093,7 @@ var WebGLRenderer = new Class({ */ removeBlendMode: function (index) { - if (index > 16 && this.blendModes[index]) + if (index > 17 && this.blendModes[index]) { this.blendModes.splice(index, 1); } From ceb9910780ee5fd7a49a2e9843cfd1fa22f69265 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sat, 10 Nov 2018 04:22:47 +0000 Subject: [PATCH 3/3] Added `erase` method for clearing parts of a Render Texture. --- .../rendertexture/RenderTexture.js | 92 ++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/src/gameobjects/rendertexture/RenderTexture.js b/src/gameobjects/rendertexture/RenderTexture.js index ff521956d..ebbfb0360 100644 --- a/src/gameobjects/rendertexture/RenderTexture.js +++ b/src/gameobjects/rendertexture/RenderTexture.js @@ -4,6 +4,7 @@ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ +var BlendModes = require('../../renderer/BlendModes'); var Camera = require('../../cameras/2d/BaseCamera'); var CanvasPool = require('../../display/canvas/CanvasPool'); var Class = require('../../utils/Class'); @@ -188,6 +189,16 @@ var RenderTexture = new Class({ */ this._saved = false; + /** + * Internal erase mode flag. + * + * @name Phaser.GameObjects.RenderTexture#_eraseMode + * @type {boolean} + * @private + * @since 3.16.0 + */ + this._eraseMode = false; + /** * An internal Camera that can be used to move around the Render Texture. * Control it just like you would any Scene Camera. The difference is that it only impacts the placement of what @@ -464,6 +475,70 @@ var RenderTexture = new Class({ return this; }, + /** + * Draws the given object, or an array of objects, to this Render Texture using a blend mode of ERASE. + * This has the effect of erasing any filled pixels in the objects from this Render Texture. + * + * It can accept any of the following: + * + * * Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite. + * * Dynamic and Static Tilemap Layers. + * * A Group. The contents of which will be iterated and drawn in turn. + * * A Container. The contents of which will be iterated fully, and drawn in turn. + * * A Scene's Display List. Pass in `Scene.children` to draw the whole list. + * * Another Render Texture. + * * A Texture Frame instance. + * * A string. This is used to look-up a texture from the Texture Manager. + * + * Note: You cannot erase a Render Texture from itself. + * + * If passing in a Group or Container it will only draw children that return `true` + * when their `willRender()` method is called. I.e. a Container with 10 children, + * 5 of which have `visible=false` will only draw the 5 visible ones. + * + * If passing in an array of Game Objects it will draw them all, regardless if + * they pass a `willRender` check or not. + * + * You can pass in a string in which case it will look for a texture in the Texture + * Manager matching that string, and draw the base frame. + * + * You can pass in the `x` and `y` coordinates to draw the objects at. The use of + * the coordinates differ based on what objects are being drawn. If the object is + * a Group, Container or Display List, the coordinates are _added_ to the positions + * of the children. For all other types of object, the coordinates are exact. + * + * Calling this method causes the WebGL batch to flush, so it can write the texture + * data to the framebuffer being used internally. The batch is flushed at the end, + * after the entries have been iterated. So if you've a bunch of objects to draw, + * try and pass them in an array in one single call, rather than making lots of + * separate calls. + * + * @method Phaser.GameObjects.RenderTexture#erase + * @since 3.16.0 + * + * @param {any} entries - Any renderable Game Object, or Group, Container, Display List, other Render Texture, Texture Frame or an array of any of these. + * @param {number} [x] - The x position to draw the Frame at, or the offset applied to the object. + * @param {number} [y] - The y position to draw the Frame at, or the offset applied to the object. + * + * @return {this} This Render Texture instance. + */ + erase: function (entries, x, y) + { + this._eraseMode = true; + + var blendMode = this.renderer.currentBlendMode; + + this.renderer.setBlendMode(BlendModes.ERASE); + + this.draw(entries, x, y, 1, 16777215); + + this.renderer.setBlendMode(blendMode); + + this._eraseMode = false; + + return this; + }, + /** * Draws the given object, or an array of objects, to this Render Texture. * @@ -748,7 +823,10 @@ var RenderTexture = new Class({ var prevX = gameObject.x; var prevY = gameObject.y; - this.renderer.setBlendMode(gameObject.blendMode); + if (!this._eraseMode) + { + this.renderer.setBlendMode(gameObject.blendMode); + } gameObject.setPosition(x, y); @@ -828,7 +906,19 @@ var RenderTexture = new Class({ if (this.gl) { + if (this._eraseMode) + { + var blendMode = this.renderer.currentBlendMode; + + this.renderer.setBlendMode(BlendModes.ERASE); + } + this.pipeline.batchTextureFrame(textureFrame, x, y, tint, alpha, this.camera.matrix, null); + + if (this._eraseMode) + { + this.renderer.setBlendMode(blendMode); + } } else {