Skip to content

Commit 1ffb559

Browse files
committed
Added revised up down handlers
1 parent 7992dfd commit 1ffb559

3 files changed

Lines changed: 94 additions & 5 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '99c41320-6dbd-11e7-9fef-ffd37d0720d9'
2+
build: '39e871e0-6dc1-11e7-8a70-9f91dc27e295'
33
};
44
module.exports = CHECKSUM;

v3/src/input/local/components/Update.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ var Update = function (time, delta)
4646
// This is run regardless if the pointer has moved so we capture moving Game Objects
4747
this.processOverOutEvents(pointer, results);
4848

49-
// if (pointer.justUp || pointer.justDown)
50-
// {
51-
// this.processUpDownEvents(pointer, results);
52-
// }
49+
if (pointer.justUp)
50+
{
51+
this.processUpEvents(pointer, results);
52+
}
53+
54+
if (pointer.justDown)
55+
{
56+
this.processDownEvents(pointer, results);
57+
}
5358

5459
// if (pointer.justMoved)
5560
// {

v3/src/plugins/InputManager.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,90 @@ var InputManager = new Class({
1313
SceneInputManager.call(this, scene, game);
1414
},
1515

16+
processUpEvents: function (pointer, currentlyOver)
17+
{
18+
// If the pointer is released we need to reset all 'isDown' IOs, regardless if pointer is still over them or not
19+
// Also concat in the currentlyOver, so we can dispatch an UP event for an IO that has the pointer over it.
20+
// For example if you click down outside a sprite, hold down, move over the sprite, then release, the sprite will
21+
// still fire an UP event, even though it never previously received a DOWN event.
22+
var previouslyDown = this.children.down[pointer.id].concat(currentlyOver);
23+
24+
if (previouslyDown.length === 0)
25+
{
26+
// Dispatch UP event, even though nothing was down previously
27+
this.events.dispatch(new InputEvent.UP(pointer));
28+
}
29+
else
30+
{
31+
// Go through all objects the pointer was previously down on and set to up
32+
for (var i = 0; i < previouslyDown.length; i++)
33+
{
34+
var interactiveObject = previouslyDown[i];
35+
36+
if (!this.topOnly || (this.topOnly && i === 0))
37+
{
38+
this.events.dispatch(new InputEvent.UP(pointer, interactiveObject.gameObject, previouslyDown));
39+
}
40+
41+
this.childOnUp(i, pointer, interactiveObject);
42+
}
43+
}
44+
45+
// Reset the down array
46+
this.children.down[pointer.id].length = 0;
47+
},
48+
49+
processDownEvents: function (pointer, currentlyOver)
50+
{
51+
if (currentlyOver.length === 0)
52+
{
53+
// Dispatch DOWN event, even though nothing was below the pointer
54+
this.events.dispatch(new InputEvent.DOWN(pointer));
55+
}
56+
else
57+
{
58+
// Go through all objects the pointer was over and set them to down
59+
for (var i = 0; i < currentlyOver.length; i++)
60+
{
61+
var interactiveObject = currentlyOver[i];
62+
63+
this.events.dispatch(new InputEvent.DOWN(pointer, interactiveObject.gameObject, currentlyOver));
64+
65+
this.childOnDown(pointer, interactiveObject);
66+
67+
if (this.topOnly)
68+
{
69+
break;
70+
}
71+
}
72+
}
73+
},
74+
75+
childOnUp: function (index, pointer, interactiveObject)
76+
{
77+
interactiveObject.isDown = false;
78+
79+
// If we are not processing topOnly items, or we are and this IS the topmost item, then hit it
80+
if (!this.topOnly || (this.topOnly && index === 0))
81+
{
82+
interactiveObject.onUp(interactiveObject.gameObject, pointer);
83+
}
84+
},
85+
86+
childOnDown: function (pointer, interactiveObject)
87+
{
88+
interactiveObject.isDown = true;
89+
90+
interactiveObject.onDown(interactiveObject.gameObject, pointer, interactiveObject.localX, interactiveObject.localY);
91+
92+
this.children.down[pointer.id].push(interactiveObject);
93+
94+
// if (input.draggable && !input.isDragged)
95+
// {
96+
// this.gameObjectOnDragStart(pointer, gameObject);
97+
// }
98+
},
99+
16100
/*
17101
processOverOutEvents: function (pointer, currentlyOver)
18102
{

0 commit comments

Comments
 (0)