Skip to content

Commit a65f9c7

Browse files
committed
Group.onChildInputDown is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an onInputDown signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.
Group.onChildInputUp is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputUp` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it. Group.onChildInputOver is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputOver` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it. Group.onChildInputOut is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputOut` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.
1 parent 28331c4 commit a65f9c7

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
357357
* Pointer.interactiveCandidates is a new Array that is erased and re-populated every time this Pointer is updated. It contains references to all of the Game Objects that were considered as being valid for processing by this Pointer, during the most recent update. To be valid they must have suitable a `priorityID`, be Input enabled, be visible and actually have the Pointer over them. You can check the contents of this array in events such as `onInputDown`, but beware: it is reset every update.
358358
* Pointer.swapTarget allows you to change the `Pointer.targetObject` object to be the one provided. This allows you to have fine-grained control over which object the Pointer is targeting.
359359
* Input.setInteractiveCandidateHandler allows you to add a callback that is fired every time `Pointer.processInteractiveObjects` is called. The purpose of `processInteractiveObjects` is to work out which Game Object the Pointer is going to interact with. It works by polling all of the valid game objects, and then slowly discounting those that don't meet the criteria (i.e. they aren't under the Pointer, are disabled, invisible, etc). Eventually a short-list of 'candidates' is created. These are all of the Game Objects which are valid for input and overlap with the Pointer. If you need fine-grained control over which of the items is selected then you can use this callback to do so. The callback will be sent 3 parameters: 1) A reference to the Phaser.Pointer object that is processing the Items. 2) An array containing all potential interactive candidates. This is an array of `InputHandler` objects, not Sprites. 3) The current 'favorite' candidate, based on its priorityID and position in the display list. Your callback MUST return one of the candidates sent to it.
360+
* Group.onChildInputDown is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputDown` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.
361+
* Group.onChildInputUp is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputUp` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.
362+
* Group.onChildInputOver is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputOver` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.
363+
* Group.onChildInputOut is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputOut` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.
360364

361365
### Updates
362366

src/core/Group.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,55 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
148148
*/
149149
this.inputEnableChildren = false;
150150

151+
/**
152+
* This Signal is dispatched whenever a child of this Group emits an onInputDown signal as a result
153+
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
154+
* every child Sprite.
155+
*
156+
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
157+
* a reference to the Pointer that caused it.
158+
*
159+
* @property {Phaser.Signal} onChildInputDown
160+
*/
161+
this.onChildInputDown = new Phaser.Signal();
162+
163+
/**
164+
* This Signal is dispatched whenever a child of this Group emits an onInputUp signal as a result
165+
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
166+
* every child Sprite.
167+
*
168+
* This Signal is sent 3 arguments: A reference to the Sprite that triggered the signal,
169+
* a reference to the Pointer that caused it, and a boolean value `isOver` that tells you if the Pointer
170+
* is still over the Sprite or not.
171+
*
172+
* @property {Phaser.Signal} onChildInputUp
173+
*/
174+
this.onChildInputUp = new Phaser.Signal();
175+
176+
/**
177+
* This Signal is dispatched whenever a child of this Group emits an onInputOver signal as a result
178+
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
179+
* every child Sprite.
180+
*
181+
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
182+
* a reference to the Pointer that caused it.
183+
*
184+
* @property {Phaser.Signal} onChildInputOver
185+
*/
186+
this.onChildInputOver = new Phaser.Signal();
187+
188+
/**
189+
* This Signal is dispatched whenever a child of this Group emits an onInputOut signal as a result
190+
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
191+
* every child Sprite.
192+
*
193+
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
194+
* a reference to the Pointer that caused it.
195+
*
196+
* @property {Phaser.Signal} onChildInputOut
197+
*/
198+
this.onChildInputOut = new Phaser.Signal();
199+
151200
/**
152201
* If true all Sprites created by, or added to this group, will have a physics body enabled on them.
153202
*

src/input/InputHandler.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@ Phaser.InputHandler.prototype = {
962962
{
963963
this.sprite.events.onInputOver$dispatch(this.sprite, pointer);
964964
}
965+
966+
if (this.sprite.parent && this.sprite.parent.type === Phaser.GROUP)
967+
{
968+
this.sprite.parent.onChildInputOver.dispatch(this.sprite, pointer);
969+
}
965970
}
966971

967972
},
@@ -997,6 +1002,11 @@ Phaser.InputHandler.prototype = {
9971002
if (!silent && this.sprite && this.sprite.events)
9981003
{
9991004
this.sprite.events.onInputOut$dispatch(this.sprite, pointer);
1005+
1006+
if (this.sprite && this.sprite.parent && this.sprite.parent.type === Phaser.GROUP)
1007+
{
1008+
this.sprite.parent.onChildInputOut.dispatch(this.sprite, pointer);
1009+
}
10001010
}
10011011

10021012
},
@@ -1038,7 +1048,13 @@ Phaser.InputHandler.prototype = {
10381048
{
10391049
this.sprite.events.onInputDown$dispatch(this.sprite, pointer);
10401050

1041-
// The onInputDown event might have destroyed this sprite.
1051+
// The event above might have destroyed this sprite.
1052+
if (this.sprite && this.sprite.parent && this.sprite.parent.type === Phaser.GROUP)
1053+
{
1054+
this.sprite.parent.onChildInputDown.dispatch(this.sprite, pointer);
1055+
}
1056+
1057+
// The events might have destroyed this sprite.
10421058
if (this.sprite === null)
10431059
{
10441060
return;
@@ -1134,6 +1150,11 @@ Phaser.InputHandler.prototype = {
11341150
this.sprite.events.onInputUp$dispatch(this.sprite, pointer, isOver);
11351151
}
11361152

1153+
if (this.sprite && this.sprite.parent && this.sprite.parent.type === Phaser.GROUP)
1154+
{
1155+
this.sprite.parent.onChildInputUp.dispatch(this.sprite, pointer, isOver);
1156+
}
1157+
11371158
// The onInputUp event may have changed the sprite so that checkPointerOver is no longer true, so update it.
11381159
if (isOver)
11391160
{

0 commit comments

Comments
 (0)