Skip to content

Commit a0c3c3f

Browse files
authored
Merge pull request #213 from paulkaplan/touching-invisible
Ignore sprite visibility when testing for touching color
2 parents 71e8a23 + 43aa62e commit a0c3c3f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/RenderWebGL.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ class RenderWebGL extends EventEmitter {
424424

425425
/**
426426
* Check if a particular Drawable is touching a particular color.
427+
* Unlike touching drawable, touching color tests invisible sprites.
427428
* @param {int} drawableID The ID of the Drawable to check.
428429
* @param {Array<int>} color3b Test if the Drawable is touching this color.
429430
* @param {Array<int>} [mask3b] Optionally mask the check to this part of Drawable.
@@ -435,11 +436,11 @@ class RenderWebGL extends EventEmitter {
435436

436437
const bounds = this._touchingBounds(drawableID);
437438
if (!bounds) {
438-
return;
439+
return false;
439440
}
440441
const candidateIDs = this._filterCandidatesTouching(drawableID, this._drawList, bounds);
441442
if (!candidateIDs) {
442-
return;
443+
return false;
443444
}
444445

445446
// Limit size of viewport to the bounds around the target Drawable,
@@ -477,7 +478,10 @@ class RenderWebGL extends EventEmitter {
477478
ShaderManager.DRAW_MODE.colorMask :
478479
ShaderManager.DRAW_MODE.silhouette,
479480
projection,
480-
{extraUniforms});
481+
{
482+
extraUniforms,
483+
ignoreVisibility: true // Touching color ignores sprite visibility
484+
});
481485

482486
gl.stencilFunc(gl.EQUAL, 1, 1);
483487
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
@@ -533,11 +537,11 @@ class RenderWebGL extends EventEmitter {
533537

534538
const bounds = this._touchingBounds(drawableID);
535539
if (!bounds) {
536-
return;
540+
return false;
537541
}
538542
candidateIDs = this._filterCandidatesTouching(drawableID, candidateIDs, bounds);
539543
if (!candidateIDs) {
540-
return;
544+
return false;
541545
}
542546

543547
// Limit size of viewport to the bounds around the target Drawable,
@@ -1003,7 +1007,7 @@ class RenderWebGL extends EventEmitter {
10031007

10041008
try {
10051009
gl.disable(gl.BLEND);
1006-
this._drawThese([stampID], ShaderManager.DRAW_MODE.default, projection, {isStamping: true});
1010+
this._drawThese([stampID], ShaderManager.DRAW_MODE.default, projection, {ignoreVisibility: true});
10071011
} finally {
10081012
gl.enable(gl.BLEND);
10091013
}
@@ -1097,7 +1101,7 @@ class RenderWebGL extends EventEmitter {
10971101
* @param {idFilterFunc} opts.filter An optional filter function.
10981102
* @param {object.<string,*>} opts.extraUniforms Extra uniforms for the shaders.
10991103
* @param {int} opts.effectMask Bitmask for effects to allow
1100-
* @param {boolean} opts.isStamping Stamp mode ignores sprite visibility, always drawing.
1104+
* @param {boolean} opts.ignoreVisibility Draw all, despite visibility (e.g. stamping, touching color)
11011105
* @private
11021106
*/
11031107
_drawThese (drawables, drawMode, projection, opts = {}) {
@@ -1114,8 +1118,9 @@ class RenderWebGL extends EventEmitter {
11141118
const drawable = this._allDrawables[drawableID];
11151119
/** @todo check if drawable is inside the viewport before anything else */
11161120

1117-
// Hidden drawables (e.g., by a "hide" block) are not drawn unless stamping
1118-
if (!drawable.getVisible() && !opts.isStamping) continue;
1121+
// Hidden drawables (e.g., by a "hide" block) are not drawn unless
1122+
// the ignoreVisibility flag is used (e.g. for stamping or touchingColor).
1123+
if (!drawable.getVisible() && !opts.ignoreVisibility) continue;
11191124

11201125
const drawableScale = drawable.scale;
11211126

0 commit comments

Comments
 (0)