mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
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.
This commit is contained in:
parent
28331c4f7f
commit
a65f9c7e4b
3 changed files with 75 additions and 1 deletions
|
@ -357,6 +357,10 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
|
||||||
* 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.
|
* 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.
|
||||||
* 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.
|
* 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.
|
||||||
* 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.
|
* 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.
|
||||||
|
* 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.
|
||||||
|
|
||||||
### Updates
|
### Updates
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,55 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
|
||||||
*/
|
*/
|
||||||
this.inputEnableChildren = false;
|
this.inputEnableChildren = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Signal is dispatched whenever a child of this Group emits an onInputDown signal as a result
|
||||||
|
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
|
||||||
|
* every child Sprite.
|
||||||
|
*
|
||||||
|
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
|
||||||
|
* a reference to the Pointer that caused it.
|
||||||
|
*
|
||||||
|
* @property {Phaser.Signal} onChildInputDown
|
||||||
|
*/
|
||||||
|
this.onChildInputDown = new Phaser.Signal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Signal is dispatched whenever a child of this Group emits an onInputUp signal as a result
|
||||||
|
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
|
||||||
|
* every child Sprite.
|
||||||
|
*
|
||||||
|
* This Signal is sent 3 arguments: A reference to the Sprite that triggered the signal,
|
||||||
|
* a reference to the Pointer that caused it, and a boolean value `isOver` that tells you if the Pointer
|
||||||
|
* is still over the Sprite or not.
|
||||||
|
*
|
||||||
|
* @property {Phaser.Signal} onChildInputUp
|
||||||
|
*/
|
||||||
|
this.onChildInputUp = new Phaser.Signal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Signal is dispatched whenever a child of this Group emits an onInputOver signal as a result
|
||||||
|
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
|
||||||
|
* every child Sprite.
|
||||||
|
*
|
||||||
|
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
|
||||||
|
* a reference to the Pointer that caused it.
|
||||||
|
*
|
||||||
|
* @property {Phaser.Signal} onChildInputOver
|
||||||
|
*/
|
||||||
|
this.onChildInputOver = new Phaser.Signal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Signal is dispatched whenever a child of this Group emits an onInputOut signal as a result
|
||||||
|
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
|
||||||
|
* every child Sprite.
|
||||||
|
*
|
||||||
|
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
|
||||||
|
* a reference to the Pointer that caused it.
|
||||||
|
*
|
||||||
|
* @property {Phaser.Signal} onChildInputOut
|
||||||
|
*/
|
||||||
|
this.onChildInputOut = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true all Sprites created by, or added to this group, will have a physics body enabled on them.
|
* If true all Sprites created by, or added to this group, will have a physics body enabled on them.
|
||||||
*
|
*
|
||||||
|
|
|
@ -962,6 +962,11 @@ Phaser.InputHandler.prototype = {
|
||||||
{
|
{
|
||||||
this.sprite.events.onInputOver$dispatch(this.sprite, pointer);
|
this.sprite.events.onInputOver$dispatch(this.sprite, pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.sprite.parent && this.sprite.parent.type === Phaser.GROUP)
|
||||||
|
{
|
||||||
|
this.sprite.parent.onChildInputOver.dispatch(this.sprite, pointer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -997,6 +1002,11 @@ Phaser.InputHandler.prototype = {
|
||||||
if (!silent && this.sprite && this.sprite.events)
|
if (!silent && this.sprite && this.sprite.events)
|
||||||
{
|
{
|
||||||
this.sprite.events.onInputOut$dispatch(this.sprite, pointer);
|
this.sprite.events.onInputOut$dispatch(this.sprite, pointer);
|
||||||
|
|
||||||
|
if (this.sprite && this.sprite.parent && this.sprite.parent.type === Phaser.GROUP)
|
||||||
|
{
|
||||||
|
this.sprite.parent.onChildInputOut.dispatch(this.sprite, pointer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -1038,7 +1048,13 @@ Phaser.InputHandler.prototype = {
|
||||||
{
|
{
|
||||||
this.sprite.events.onInputDown$dispatch(this.sprite, pointer);
|
this.sprite.events.onInputDown$dispatch(this.sprite, pointer);
|
||||||
|
|
||||||
// The onInputDown event might have destroyed this sprite.
|
// The event above might have destroyed this sprite.
|
||||||
|
if (this.sprite && this.sprite.parent && this.sprite.parent.type === Phaser.GROUP)
|
||||||
|
{
|
||||||
|
this.sprite.parent.onChildInputDown.dispatch(this.sprite, pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The events might have destroyed this sprite.
|
||||||
if (this.sprite === null)
|
if (this.sprite === null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -1134,6 +1150,11 @@ Phaser.InputHandler.prototype = {
|
||||||
this.sprite.events.onInputUp$dispatch(this.sprite, pointer, isOver);
|
this.sprite.events.onInputUp$dispatch(this.sprite, pointer, isOver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.sprite && this.sprite.parent && this.sprite.parent.type === Phaser.GROUP)
|
||||||
|
{
|
||||||
|
this.sprite.parent.onChildInputUp.dispatch(this.sprite, pointer, isOver);
|
||||||
|
}
|
||||||
|
|
||||||
// The onInputUp event may have changed the sprite so that checkPointerOver is no longer true, so update it.
|
// The onInputUp event may have changed the sprite so that checkPointerOver is no longer true, so update it.
|
||||||
if (isOver)
|
if (isOver)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue