Paskuda13 Posted July 4, 2017 Share Posted July 4, 2017 Just noticed an issue. Lets say we have a group named OurGroup with three buttons (represents settings window with buttons 'soundOn', 'pause', 'close'). Each button have its own inputDown listener (or any else like inputOver, inputOut etc.). Then we add this group to the game via this.game.add.group(ourGroup) It works perfect, all the buttons are clickable and so on. Some time later, we want to remove the group from the game (i.e. user clicked the close button on our window) by itself: /*somewhere in the OurGroup class*/ if(this.parent) { this.parent.removeChild(this); } OK, the OurGroup has succesfully removed from the game, it's invisible. But! The listeners attached to the group's buttons are still active and react the input events! Could someone explain me is it a bug or I'm doing something wrong? I migrated to Phaser from flash, and there after have removed a DisplayObject from a stage, all listeners attached to it were removed as well. Link to comment Share on other sites More sharing options...
Antriel Posted July 4, 2017 Share Posted July 4, 2017 1 minute ago, Paskuda13 said: I migrated to Phaser from flash, and there after have removed a DisplayObject from a stage, all listeners attached to it were removed as well. Were they? IIRC they were not by default. Unless you used the optional parameter to set it as a weak listener and the object was gc-ed. Although in case of buttons, they indeed would not trigger (because they weren't in display list). The listeners would stay there though. Not sure how Phaser does it, but I expect the listeners to stay connected (although possibly not triggering as you can't really 'inputOver' them). Maybe `group.destroy()` will work? Not sure Link to comment Share on other sites More sharing options...
Paskuda13 Posted July 4, 2017 Author Share Posted July 4, 2017 13 minutes ago, Antriel said: Were they? IIRC they were not by default. Unless you used the optional parameter to set it as a weak listener and the object was gc-ed. Although in case of buttons, they indeed would not trigger (because they weren't in display list). The listeners would stay there though. Of course, I meant the listeners were active but didn't trigger when the button was removed from dispolay list. But here, in Phaser, they are still triggering even if they aren't in the display list. It's extremely illogically for me About group.destroy(), it works as you said, it removes the listeners as well, but in my case i'd like not to remove the window and re-create it each time. P.S. BTW, after removing the group I tried to set ourGroup.visible = false and, suddenly, it disabled the listeners! WTF? Why, why removing the group from stage (or world) left them active, but just setting group.visible to false - disables them?? Link to comment Share on other sites More sharing options...
samme Posted July 4, 2017 Share Posted July 4, 2017 When processing input events, Phaser checks that the input handler's sprite is visible; the sprite has a parent; and the parent is visible. It doesn't check that the parent also has a parent, or has the Stage as an ancestor. For your case ourGroup.visible = false seems a good choice. Link to comment Share on other sites More sharing options...
Recommended Posts