mirror of
https://github.com/wassname/phaser.git
synced 2026-07-23 13:00:41 +08:00
Input Handler 90% there.
This commit is contained in:
+5
-7
@@ -370,7 +370,7 @@ Phaser.Input.prototype = {
|
||||
**/
|
||||
reset: function (hard) {
|
||||
|
||||
if (typeof hard === "undefined") { hard = false; }
|
||||
hard = hard || false;
|
||||
|
||||
this.keyboard.reset();
|
||||
this.mousePointer.reset();
|
||||
@@ -428,7 +428,8 @@ Phaser.Input.prototype = {
|
||||
**/
|
||||
startPointer: function (event) {
|
||||
|
||||
if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers) {
|
||||
if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -525,7 +526,7 @@ Phaser.Input.prototype = {
|
||||
**/
|
||||
getPointer: function (state) {
|
||||
|
||||
if (typeof state === "undefined") { state = false; }
|
||||
state = state || false;
|
||||
|
||||
if (this.pointer1.active == state)
|
||||
{
|
||||
@@ -599,10 +600,7 @@ Phaser.Input.prototype = {
|
||||
**/
|
||||
getAngle: function (pointer1, pointer2) {
|
||||
// return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
|
||||
},
|
||||
|
||||
addGameObject: function() {},
|
||||
removeGameObject: function() {},
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ Phaser.InputHandler.prototype = {
|
||||
this.enabled = true;
|
||||
|
||||
// Create the signals the Input component will emit
|
||||
if (this.sprites.events && this.sprite.events.onInputOver == null)
|
||||
if (this.sprite.events && this.sprite.events.onInputOver == null)
|
||||
{
|
||||
this.sprite.events.onInputOver = new Phaser.Signal;
|
||||
this.sprite.events.onInputOut = new Phaser.Signal;
|
||||
@@ -316,13 +316,13 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given pointer is over this Sprite. All checks are done in world coordinates.
|
||||
* Checks if the given pointer is over this Sprite.
|
||||
*/
|
||||
checkPointerOver: function (pointer) {
|
||||
|
||||
if (this.enabled && this.sprite.visible)
|
||||
{
|
||||
this.sprite.getLocalPosition(this._tempPoint, pointer.x, pointer.y);
|
||||
this.sprite.getLocalUnmodifiedPosition(this._tempPoint, pointer.x, pointer.y);
|
||||
|
||||
// Check against bounds
|
||||
var width = this.sprite.texture.frame.width,
|
||||
@@ -330,11 +330,11 @@ Phaser.InputHandler.prototype = {
|
||||
x1 = -width * this.sprite.anchor.x,
|
||||
y1;
|
||||
|
||||
if(x > x1 && x < x1 + width)
|
||||
if (this._tempPoint.x > x1 && this._tempPoint.x < x1 + width)
|
||||
{
|
||||
y1 = -height * this.sprite.anchor.y;
|
||||
|
||||
if(y > y1 && y < y1 + height)
|
||||
if (this._tempPoint.y > y1 && this._tempPoint.y < y1 + height)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -364,7 +364,7 @@ Phaser.InputHandler.prototype = {
|
||||
}
|
||||
else if (this._pointerData[pointer.id].isOver == true)
|
||||
{
|
||||
if (Phaser.SpriteUtils.overlapsPointer(this.sprite, pointer))
|
||||
if (this.checkPointerOver(pointer))
|
||||
{
|
||||
this._pointerData[pointer.id].x = pointer.x - this.sprite.x;
|
||||
this._pointerData[pointer.id].y = pointer.y - this.sprite.y;
|
||||
@@ -449,7 +449,7 @@ Phaser.InputHandler.prototype = {
|
||||
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
|
||||
|
||||
// Only release the InputUp signal if the pointer is still over this sprite
|
||||
if (Phaser.SpriteUtils.overlapsPointer(this.sprite, pointer))
|
||||
if (this.checkPointerOver(pointer))
|
||||
{
|
||||
//console.log('releasedHandler: ' + Date.now());
|
||||
this.sprite.events.onInputUp.dispatch(this.sprite, pointer);
|
||||
|
||||
+29
-33
@@ -259,7 +259,7 @@ Phaser.Pointer.prototype = {
|
||||
|
||||
if (this.targetObject !== null)
|
||||
{
|
||||
this.targetObject.input._touchedHandler(this);
|
||||
this.targetObject._touchedHandler(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -349,9 +349,9 @@ Phaser.Pointer.prototype = {
|
||||
}
|
||||
|
||||
// Easy out if we're dragging something and it still exists
|
||||
if (this.targetObject !== null && this.targetObject.input && this.targetObject.input.isDragged == true)
|
||||
if (this.targetObject !== null && this.targetObject.isDragged == true)
|
||||
{
|
||||
if (this.targetObject.input.update(this) == false)
|
||||
if (this.targetObject.update(this) == false)
|
||||
{
|
||||
this.targetObject = null;
|
||||
}
|
||||
@@ -366,47 +366,36 @@ Phaser.Pointer.prototype = {
|
||||
this._highestInputPriorityID = -1;
|
||||
|
||||
// Just run through the linked list
|
||||
if (this.game.input.interactiveItems.next)
|
||||
if (this.game.input.interactiveItems.total > 0)
|
||||
{
|
||||
var currentNode = this.game.input.interactiveItems.next;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
// If the object has a higher InputManager.PriorityID OR if the priority ID is the same as the current highest AND it has a higher renderOrderID, then set it to the top
|
||||
if (currentNode.priorityID > this._highestInputPriorityID || (currentNode.priorityID == this._highestInputPriorityID && currentNode.sprite.renderOrderID > this._highestRenderOrderID) && currentNode.checkPointerOver(this))
|
||||
if (currentNode.priorityID > this._highestInputPriorityID || (currentNode.priorityID == this._highestInputPriorityID && currentNode.sprite.renderOrderID > this._highestRenderOrderID))
|
||||
{
|
||||
this._highestRenderOrderID = currentNode.sprite.renderOrderID;
|
||||
this._highestInputPriorityID = currentNode.priorityID;
|
||||
this._highestRenderObject = currentNode;
|
||||
if (currentNode.checkPointerOver(this))
|
||||
{
|
||||
// console.log('HRO set', currentNode.sprite.name);
|
||||
this._highestRenderOrderID = currentNode.sprite.renderOrderID;
|
||||
this._highestInputPriorityID = currentNode.priorityID;
|
||||
this._highestRenderObject = currentNode;
|
||||
}
|
||||
}
|
||||
|
||||
currentNode = currentNode.next;
|
||||
}
|
||||
while (currentNode != this.game.input.interactiveItems.next)
|
||||
while (currentNode != null)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
{
|
||||
if (this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this))
|
||||
{
|
||||
// If the object has a higher InputManager.PriorityID OR if the priority ID is the same as the current highest AND it has a higher renderOrderID, then set it to the top
|
||||
if (this.game.input.inputObjects[i].input.priorityID > this._highestInputPriorityID || (this.game.input.inputObjects[i].input.priorityID == this._highestInputPriorityID && this.game.input.inputObjects[i].renderOrderID > this._highestRenderOrderID))
|
||||
{
|
||||
this._highestRenderOrderID = this.game.input.inputObjects[i].renderOrderID;
|
||||
this._highestRenderObject = i;
|
||||
this._highestInputPriorityID = this.game.input.inputObjects[i].input.priorityID;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (this._highestRenderObject == null)
|
||||
{
|
||||
// console.log("HRO null");
|
||||
|
||||
// The pointer isn't currently over anything, check if we've got a lingering previous target
|
||||
if (this.targetObject)
|
||||
{
|
||||
// console.log("The pointer isn't currently over anything, check if we've got a lingering previous target");
|
||||
this.targetObject._pointerOutHandler(this);
|
||||
this.targetObject = null;
|
||||
}
|
||||
@@ -416,15 +405,18 @@ Phaser.Pointer.prototype = {
|
||||
if (this.targetObject == null)
|
||||
{
|
||||
// And now set the new one
|
||||
// console.log('And now set the new one');
|
||||
this.targetObject = this._highestRenderObject;
|
||||
this._highestRenderObject._pointerOverHandler(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We've got a target from the last update
|
||||
// console.log("We've got a target from the last update");
|
||||
if (this.targetObject == this._highestRenderObject)
|
||||
{
|
||||
// Same target as before, so update it
|
||||
// console.log("Same target as before, so update it");
|
||||
if (this._highestRenderObject.update(this) == false)
|
||||
{
|
||||
this.targetObject = null;
|
||||
@@ -433,6 +425,7 @@ Phaser.Pointer.prototype = {
|
||||
else
|
||||
{
|
||||
// The target has changed, so tell the old one we've left it
|
||||
// console.log("The target has changed, so tell the old one we've left it");
|
||||
this.targetObject._pointerOutHandler(this);
|
||||
|
||||
// And now set the new one
|
||||
@@ -511,17 +504,20 @@ Phaser.Pointer.prototype = {
|
||||
this.game.input.currentPointers--;
|
||||
}
|
||||
|
||||
if (this.game.input.interactiveItems.next)
|
||||
if (this.game.input.interactiveItems.total > 0)
|
||||
{
|
||||
var currentNode = this.game.input.interactiveItems.next;
|
||||
|
||||
do
|
||||
{
|
||||
currentNode._releasedHandler(this);
|
||||
if (currentNode)
|
||||
{
|
||||
currentNode._releasedHandler(this);
|
||||
}
|
||||
|
||||
currentNode = currentNode.next;
|
||||
}
|
||||
while (currentNode != this.game.input.interactiveItems.next)
|
||||
while (currentNode != null)
|
||||
}
|
||||
|
||||
if (this.targetObject)
|
||||
@@ -631,7 +627,7 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldX", {
|
||||
*/
|
||||
get: function () {
|
||||
|
||||
return this.game.world.camera.worldView.x + this.x;
|
||||
return this.game.world.camera.x + this.x;
|
||||
|
||||
},
|
||||
|
||||
@@ -647,7 +643,7 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldY", {
|
||||
*/
|
||||
get: function () {
|
||||
|
||||
return this.game.world.camera.worldView.y + this.y;
|
||||
return this.game.world.camera.y + this.y;
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user