From 719a2eedca4e7f7bf44bc3a7a3ebcdb4085ceb4e Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 4 Jun 2018 21:04:27 +0100 Subject: [PATCH] Interactive Objects inside of Containers would still fire their input events even if the Container (or any ancestor) was set to be invisible. Objects now check their ancestor tree during the input cull and now properly skip input events if not visible. Fix #3620 --- CHANGELOG.md | 1 + src/input/InputManager.js | 45 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f481b8ff3..65e6e5623 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ * Fixed a method signature issue with the Animation component's `remove()` handler when `Animation`s are removed from the `AnimationManager`. This prevented removed animations from stopping correctly. * If you set Phaser to use a pre-existing Canvas element it is no longer re-added to the DOM (thanks @NQNStudios) * The `TweenManager.getTweensOf` method has been fixed to remove a potential endless loop should multiple targets be passed in to it (thanks @cyantree) +* Interactive Objects inside of Containers would still fire their input events even if the Container (or any ancestor) was set to be invisible. Objects now check their ancestor tree during the input cull and now properly skip input events if not visible. Fix #3620 (thanks @NemoStein) ### Examples, Documentation and TypeScript diff --git a/src/input/InputManager.js b/src/input/InputManager.js index f4922af51..707310894 100644 --- a/src/input/InputManager.js +++ b/src/input/InputManager.js @@ -914,6 +914,49 @@ var InputManager = new Class({ return this; }, + /** + * Checks if the given Game Object should be considered as a candidate for input or not. + * + * Checks if the Game Object has an input component that is enabled, that it will render, + * and finally, if it has a parent, that the parent parent, or any ancestor, is visible or not. + * + * @method Phaser.Input.InputManager#inputCandidate + * @private + * @since 3.10.0 + * + * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to test. + * + * @return {boolean} `true` if the Game Object should be considered for input, otherwise `false`. + */ + inputCandidate: function (gameObject) + { + var input = gameObject.input; + + if (!input || !input.enabled || !gameObject.willRender()) + { + return false; + } + + var visible = true; + var parent = gameObject.parentContainer; + + if (parent) + { + do { + if (!parent.visible) + { + visible = false; + break; + } + + parent = parent.parentContainer; + + } while (parent); + } + + return visible; + }, + /** * Performs a hit test using the given Pointer and camera, against an array of interactive Game Objects. * @@ -970,7 +1013,7 @@ var InputManager = new Class({ { var gameObject = culledGameObjects[i]; - if (!gameObject.input || !gameObject.input.enabled || !gameObject.willRender()) + if (!this.inputCandidate(gameObject)) { continue; }