Skip to content

Commit 719a2ee

Browse files
committed
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 phaserjs#3620
1 parent a804d7f commit 719a2ee

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
* 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.
8484
* If you set Phaser to use a pre-existing Canvas element it is no longer re-added to the DOM (thanks @NQNStudios)
8585
* The `TweenManager.getTweensOf` method has been fixed to remove a potential endless loop should multiple targets be passed in to it (thanks @cyantree)
86+
* 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)
8687

8788
### Examples, Documentation and TypeScript
8889

src/input/InputManager.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,49 @@ var InputManager = new Class({
914914
return this;
915915
},
916916

917+
/**
918+
* Checks if the given Game Object should be considered as a candidate for input or not.
919+
*
920+
* Checks if the Game Object has an input component that is enabled, that it will render,
921+
* and finally, if it has a parent, that the parent parent, or any ancestor, is visible or not.
922+
*
923+
* @method Phaser.Input.InputManager#inputCandidate
924+
* @private
925+
* @since 3.10.0
926+
*
927+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to test.
928+
*
929+
* @return {boolean} `true` if the Game Object should be considered for input, otherwise `false`.
930+
*/
931+
inputCandidate: function (gameObject)
932+
{
933+
var input = gameObject.input;
934+
935+
if (!input || !input.enabled || !gameObject.willRender())
936+
{
937+
return false;
938+
}
939+
940+
var visible = true;
941+
var parent = gameObject.parentContainer;
942+
943+
if (parent)
944+
{
945+
do {
946+
if (!parent.visible)
947+
{
948+
visible = false;
949+
break;
950+
}
951+
952+
parent = parent.parentContainer;
953+
954+
} while (parent);
955+
}
956+
957+
return visible;
958+
},
959+
917960
/**
918961
* Performs a hit test using the given Pointer and camera, against an array of interactive Game Objects.
919962
*
@@ -970,7 +1013,7 @@ var InputManager = new Class({
9701013
{
9711014
var gameObject = culledGameObjects[i];
9721015

973-
if (!gameObject.input || !gameObject.input.enabled || !gameObject.willRender())
1016+
if (!this.inputCandidate(gameObject))
9741017
{
9751018
continue;
9761019
}

0 commit comments

Comments
 (0)