mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 06:30:38 +00:00
Pointer Down and Up events working on Game Objects
This commit is contained in:
parent
d12522e480
commit
8bae761d75
4 changed files with 71 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '29bc3100-6824-11e7-b3dd-8943a02e40de'
|
||||
build: '8d1f7160-682b-11e7-b9b9-afea77e03fb0'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -59,9 +59,10 @@ var GlobalInputManager = new Class({
|
|||
|
||||
var len = this.queue.length;
|
||||
|
||||
// Currently just 1 pointer supported
|
||||
var pointer = this.activePointer;
|
||||
|
||||
pointer.hasMoved = false;
|
||||
pointer.reset();
|
||||
|
||||
if (!this.enabled || len === 0)
|
||||
{
|
||||
|
@ -77,28 +78,25 @@ var GlobalInputManager = new Class({
|
|||
{
|
||||
var event = queue[i];
|
||||
|
||||
// Move to CONSTs so we can do integer comparisons instead of strings
|
||||
switch (event.type)
|
||||
{
|
||||
case 'mousemove':
|
||||
|
||||
pointer.update(event);
|
||||
pointer.move(event);
|
||||
this.events.dispatch(new MouseEvent.MOVE(event));
|
||||
|
||||
break;
|
||||
|
||||
case 'mousedown':
|
||||
|
||||
pointer.isDown = true;
|
||||
pointer.update(event);
|
||||
pointer.down(event);
|
||||
this.events.dispatch(new MouseEvent.DOWN(event));
|
||||
|
||||
break;
|
||||
|
||||
case 'mouseup':
|
||||
|
||||
pointer.isDown = false;
|
||||
pointer.up(event);
|
||||
this.events.dispatch(new MouseEvent.UP(event));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,52 @@ var Pointer = new Class({
|
|||
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.hasMoved = false;
|
||||
|
||||
this.isDown = false;
|
||||
|
||||
this.dirty = false;
|
||||
|
||||
this.justDown = false;
|
||||
this.justUp = false;
|
||||
this.justMoved = false;
|
||||
},
|
||||
|
||||
update: function (event)
|
||||
reset: function ()
|
||||
{
|
||||
this.dirty = false;
|
||||
this.justDown = false;
|
||||
this.justUp = false;
|
||||
this.justMoved = false;
|
||||
},
|
||||
|
||||
move: function (event)
|
||||
{
|
||||
this.dirty = true;
|
||||
|
||||
this.x = event.x;
|
||||
this.y = event.y;
|
||||
this.hasMoved = true;
|
||||
|
||||
this.justMoved = true;
|
||||
},
|
||||
|
||||
down: function (event)
|
||||
{
|
||||
this.dirty = true;
|
||||
|
||||
this.x = event.x;
|
||||
this.y = event.y;
|
||||
|
||||
this.justDown = true;
|
||||
},
|
||||
|
||||
up: function (event)
|
||||
{
|
||||
this.dirty = true;
|
||||
|
||||
this.x = event.x;
|
||||
this.y = event.y;
|
||||
|
||||
this.justUp = true;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -91,13 +91,37 @@ var InputManager = new Class({
|
|||
}
|
||||
|
||||
// Has the pointer moved? If so we need to re-check the interactive objects per camera in this State
|
||||
if (this.manager.activePointer.hasMoved)
|
||||
if (this.manager.activePointer.dirty)
|
||||
{
|
||||
this.hitTestPointer(this.manager.activePointer);
|
||||
|
||||
this.processPointer(this.manager.activePointer);
|
||||
}
|
||||
},
|
||||
|
||||
// Has it been pressed down or released in this update?
|
||||
processPointer: function (pointer)
|
||||
{
|
||||
var i;
|
||||
var over = this._over;
|
||||
|
||||
if (pointer.justDown)
|
||||
{
|
||||
for (i = 0; i < over.length; i++)
|
||||
{
|
||||
this.events.dispatch(new InputEvent.DOWN(pointer, over[i]));
|
||||
}
|
||||
}
|
||||
else if (pointer.justUp)
|
||||
{
|
||||
for (i = 0; i < over.length; i++)
|
||||
{
|
||||
this.events.dispatch(new InputEvent.UP(pointer, over[i]));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
hitTestPointer: function (pointer)
|
||||
{
|
||||
var i;
|
||||
var tested = [];
|
||||
|
@ -143,20 +167,16 @@ var InputManager = new Class({
|
|||
// Now we can process what has happened
|
||||
for (i = 0; i < justOut.length; i++)
|
||||
{
|
||||
// Dispatch event? (include the pointer)
|
||||
this.events.dispatch(new InputEvent.OUT(pointer, justOut[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < justOver.length; i++)
|
||||
{
|
||||
// Dispatch event? (include the pointer)
|
||||
this.events.dispatch(new InputEvent.OVER(pointer, justOver[i]));
|
||||
}
|
||||
|
||||
// Store everything that is currently over
|
||||
this._over = stillOver.concat(justOver);
|
||||
|
||||
// console.log('tested', tested.length, 'justOver', justOver.length, 'justOut', justOut.length, 'stillOver', stillOver.length, '_over', this._over.length);
|
||||
},
|
||||
|
||||
add: function (child)
|
||||
|
|
Loading…
Reference in a new issue