mirror of
https://github.com/wassname/phaser.git
synced 2026-09-10 12:29:30 +08:00
Re-done the pointer handler so it respects the top-most rendered sprite in priority to anything below it, for both mouse over and click events.
This commit is contained in:
+16
-12
@@ -23,7 +23,6 @@ module Phaser {
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
this._stack = [];
|
||||
|
||||
this.mousePointer = new Pointer(this._game, 0);
|
||||
this.pointer1 = new Pointer(this._game, 1);
|
||||
@@ -57,11 +56,6 @@ module Phaser {
|
||||
*/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* Temporary click sorting stack
|
||||
*/
|
||||
private _stack;
|
||||
|
||||
/**
|
||||
* A vector object representing the previous position of the Pointer.
|
||||
* @property vector
|
||||
@@ -496,12 +490,6 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
public addToStack(item) {
|
||||
|
||||
this._stack.push(item);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all of the Pointers and Input states
|
||||
* @method reset
|
||||
@@ -511,6 +499,7 @@ module Phaser {
|
||||
|
||||
this.keyboard.reset();
|
||||
|
||||
this.mousePointer.reset();
|
||||
this.pointer1.reset();
|
||||
this.pointer2.reset();
|
||||
this.pointer3.reset();
|
||||
@@ -525,8 +514,23 @@ module Phaser {
|
||||
|
||||
this.currentPointers = 0;
|
||||
|
||||
for (var i = 0; i < this.totalTrackedObjects; i++)
|
||||
{
|
||||
this.inputObjects[i].input.reset();
|
||||
}
|
||||
|
||||
this._game.stage.canvas.style.cursor = "default";
|
||||
|
||||
this.inputObjects.length = 0;
|
||||
this.totalTrackedObjects = 0;
|
||||
|
||||
if (hard == true)
|
||||
{
|
||||
this.onDown.dispose();
|
||||
this.onUp.dispose();
|
||||
this.onTap.dispose();
|
||||
this.onHold.dispose();
|
||||
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
|
||||
+115
-18
@@ -65,6 +65,9 @@ module Phaser {
|
||||
*/
|
||||
private _nextDrop: number = 0;
|
||||
|
||||
// Monitor events outside of a state reset loop
|
||||
private _stateReset: bool = false;
|
||||
|
||||
/**
|
||||
* The Pointer ID (a number between 1 and 10, 0 is reserved for the mouse pointer specifically)
|
||||
* @property id
|
||||
@@ -253,11 +256,11 @@ module Phaser {
|
||||
}
|
||||
|
||||
/**
|
||||
* The Game Object this Pointer is currently dragging.
|
||||
* @property draggedObject
|
||||
* The Game Object this Pointer is currently over / touching / dragging.
|
||||
* @property targetObject
|
||||
* @type {Any}
|
||||
**/
|
||||
public draggedObject;
|
||||
public targetObject = null;
|
||||
|
||||
/**
|
||||
* Gets the X value of this Pointer in world coordinate space
|
||||
@@ -303,10 +306,6 @@ module Phaser {
|
||||
|
||||
this._history.length = 0;
|
||||
|
||||
this.move(event);
|
||||
|
||||
this.positionDown.setTo(this.x, this.y);
|
||||
|
||||
this.active = true;
|
||||
this.withinGame = true;
|
||||
this.isDown = true;
|
||||
@@ -314,6 +313,10 @@ module Phaser {
|
||||
this.timeDown = this.game.time.now;
|
||||
this._holdSent = false;
|
||||
|
||||
this.positionDown.setTo(this.x, this.y);
|
||||
|
||||
this.move(event);
|
||||
|
||||
if (this.game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
|
||||
{
|
||||
this.game.input.x = this.x * this.game.input.scaleX;
|
||||
@@ -321,6 +324,7 @@ module Phaser {
|
||||
this.game.input.onDown.dispatch(this);
|
||||
}
|
||||
|
||||
this._stateReset = false;
|
||||
this.totalTouches++;
|
||||
|
||||
if (this.isMouse == false)
|
||||
@@ -328,6 +332,34 @@ module Phaser {
|
||||
this.game.input.currentPointers++;
|
||||
}
|
||||
|
||||
// Build our temporary click stack
|
||||
/*
|
||||
var _highestPriority = 0;
|
||||
var _highestRenderID = 0;
|
||||
var _highestRenderObject: number = -1;
|
||||
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
{
|
||||
if (this.game.input.inputObjects[i].input.checkPointerOver(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
|
||||
{
|
||||
_highestRenderID = this.game.input.inputObjects[i].renderOrderID;
|
||||
_highestRenderObject = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (_highestRenderObject !== -1 && this._stateReset == false)
|
||||
{
|
||||
this.targetObject = this.game.input.inputObjects[_highestRenderObject];
|
||||
this.targetObject.input._touchedHandler(this);
|
||||
//_highestRenderObject.input._touchedHandler(this);
|
||||
}
|
||||
*/
|
||||
|
||||
if (this.targetObject !== null)
|
||||
{
|
||||
this.targetObject.input._touchedHandler(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
@@ -361,30 +393,46 @@ module Phaser {
|
||||
// Iterate through the tracked objects
|
||||
|
||||
// Build our temporary click stack
|
||||
/*
|
||||
var _highestPriority = 0;
|
||||
var _highestRenderID = 0;
|
||||
var _highestRenderObject = null;
|
||||
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
{
|
||||
if (this.game.input.inputObjects[i].input.enabled)
|
||||
{
|
||||
if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority)
|
||||
//if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority)
|
||||
if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
|
||||
{
|
||||
_highestPriority = this.game.input.inputObjects[i].input.priorityID;
|
||||
_highestRenderID = this.game.input.inputObjects[i].renderOrderID;
|
||||
_highestRenderObject = this.game.input.inputObjects[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isDown)
|
||||
if (_highestRenderObject !== null)
|
||||
{
|
||||
// Now update all objects with the highest priority ID (can be more than 1)
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
_highestRenderObject.input._pointerOverHandler(this);
|
||||
|
||||
if (this.isDown && this._stateReset == false)
|
||||
{
|
||||
if (this.game.input.inputObjects[i].input.priorityID == _highestPriority)
|
||||
{
|
||||
this.game.input.inputObjects[i].input._touchedHandler(this);
|
||||
}
|
||||
_highestRenderObject.input._touchedHandler(this);
|
||||
}
|
||||
|
||||
// Now update all objects with the highest priority ID (can be more than 1)
|
||||
//for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
//{
|
||||
// if (this.game.input.inputObjects[i].input.priorityID == _highestPriority)
|
||||
// {
|
||||
// if (this.game.input.inputObjects[i].input._touchedHandler(this) == false)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -425,6 +473,38 @@ module Phaser {
|
||||
this.game.input.circle.y = this.game.input.y;
|
||||
}
|
||||
|
||||
if (this.targetObject !== null)
|
||||
{
|
||||
if (this.targetObject.input.update(this) == false)
|
||||
{
|
||||
this.targetObject = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Build our temporary click stack
|
||||
var _highestRenderID = 0;
|
||||
var _highestRenderObject: number = -1;
|
||||
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
{
|
||||
if (this.game.input.inputObjects[i].input.checkPointerOver(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
|
||||
{
|
||||
_highestRenderID = this.game.input.inputObjects[i].renderOrderID;
|
||||
_highestRenderObject = i;
|
||||
}
|
||||
}
|
||||
|
||||
//console.log('pointer move', _highestRenderID);
|
||||
|
||||
if (_highestRenderObject !== -1)
|
||||
{
|
||||
console.log('setting target');
|
||||
this.targetObject = this.game.input.inputObjects[_highestRenderObject];
|
||||
this.targetObject.input._pointerOverHandler(this);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
@@ -448,6 +528,12 @@ module Phaser {
|
||||
*/
|
||||
public stop(event): Pointer {
|
||||
|
||||
if (this._stateReset)
|
||||
{
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
this.timeUp = this.game.time.now;
|
||||
|
||||
if (this.game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
|
||||
@@ -497,7 +583,12 @@ module Phaser {
|
||||
}
|
||||
}
|
||||
|
||||
this.draggedObject = null;
|
||||
if (this.targetObject)
|
||||
{
|
||||
this.targetObject.input._releasedHandler(this);
|
||||
}
|
||||
|
||||
this.targetObject = null;
|
||||
|
||||
return this;
|
||||
|
||||
@@ -547,13 +638,19 @@ module Phaser {
|
||||
*/
|
||||
public reset() {
|
||||
|
||||
this.active = false;
|
||||
if (this.isMouse == false)
|
||||
{
|
||||
this.active = false;
|
||||
}
|
||||
|
||||
this.identifier = null;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.totalTouches = 0;
|
||||
this._holdSent = false;
|
||||
this._history.length = 0;
|
||||
this._stateReset = true;
|
||||
this.targetObject = null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user