Skip to content

Commit fdf257d

Browse files
committed
Fixed Up and Down events. Working properly including with topOnly.
1 parent 1ffb559 commit fdf257d

7 files changed

Lines changed: 97 additions & 360 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: '39e871e0-6dc1-11e7-8a70-9f91dc27e295'
2+
build: '2ba7f500-6dc2-11e7-a19b-db1919761fe1'
33
};
44
module.exports = CHECKSUM;

v3/src/input/local/SceneInputManager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ var SceneInputManager = new Class({
9292
setOnUpCallback: require('./components/SetOnUpCallback'),
9393

9494
processOverOutEvents: require('./components/ProcessOverOutEvents'),
95+
processDownEvents: require('./components/ProcessDownEvents'),
96+
processUpEvents: require('./components/ProcessUpEvents'),
9597
childOnOut: require('./components/ChildOnOut'),
9698
childOnOver: require('./components/ChildOnOver'),
99+
childOnDown: require('./components/ChildOnDown'),
100+
childOnUp: require('./components/ChildOnUp'),
97101
sortInteractiveObjects: require('./components/SortInteractiveObjects'),
98102
sortIndexHandler: require('./components/SortIndexHandler'),
99103

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var ChildOnDown = function (pointer, interactiveObject)
2+
{
3+
interactiveObject.isDown = true;
4+
5+
interactiveObject.onDown(interactiveObject.gameObject, pointer, interactiveObject.localX, interactiveObject.localY);
6+
7+
this.children.down[pointer.id].push(interactiveObject);
8+
9+
// if (input.draggable && !input.isDragged)
10+
// {
11+
// this.gameObjectOnDragStart(pointer, gameObject);
12+
// }
13+
};
14+
15+
module.exports = ChildOnDown;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var ChildOnUp = function (index, pointer, interactiveObject)
2+
{
3+
interactiveObject.isDown = false;
4+
5+
// If we are not processing topOnly items, or we are and this IS the topmost item, then hit it
6+
if (!this.topOnly || (this.topOnly && index === 0))
7+
{
8+
interactiveObject.onUp(interactiveObject.gameObject, pointer);
9+
}
10+
};
11+
12+
module.exports = ChildOnUp;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var InputEvent = require('../events');
2+
3+
var ProcessDownEvents = function (pointer, currentlyOver)
4+
{
5+
if (currentlyOver.length === 0)
6+
{
7+
// Dispatch DOWN event, even though nothing was below the pointer
8+
this.events.dispatch(new InputEvent.DOWN(pointer));
9+
}
10+
else
11+
{
12+
// Go through all objects the pointer was over and set them to down
13+
for (var i = 0; i < currentlyOver.length; i++)
14+
{
15+
var interactiveObject = currentlyOver[i];
16+
17+
this.events.dispatch(new InputEvent.DOWN(pointer, interactiveObject.gameObject, currentlyOver));
18+
19+
this.childOnDown(pointer, interactiveObject);
20+
21+
if (this.topOnly)
22+
{
23+
break;
24+
}
25+
}
26+
}
27+
};
28+
29+
module.exports = ProcessDownEvents;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var InputEvent = require('../events');
2+
3+
var ProcessUpEvents = function (pointer, currentlyOver)
4+
{
5+
// If the pointer is released we need to reset all 'isDown' IOs, regardless if pointer is still over them or not
6+
// Also concat in the currentlyOver, so we can dispatch an UP event for an IO that has the pointer over it.
7+
// For example if you click down outside a sprite, hold down, move over the sprite, then release, the sprite will
8+
// still fire an UP event, even though it never previously received a DOWN event.
9+
var previouslyDown = this.children.down[pointer.id].concat(currentlyOver);
10+
11+
if (previouslyDown.length === 0)
12+
{
13+
// Dispatch UP event, even though nothing was down previously
14+
this.events.dispatch(new InputEvent.UP(pointer));
15+
}
16+
else
17+
{
18+
// Go through all objects the pointer was previously down on and set to up
19+
for (var i = 0; i < previouslyDown.length; i++)
20+
{
21+
var interactiveObject = previouslyDown[i];
22+
23+
if (!this.topOnly || (this.topOnly && i === 0))
24+
{
25+
this.events.dispatch(new InputEvent.UP(pointer, interactiveObject.gameObject, previouslyDown));
26+
}
27+
28+
this.childOnUp(i, pointer, interactiveObject);
29+
}
30+
}
31+
32+
// Reset the down array
33+
this.children.down[pointer.id].length = 0;
34+
};
35+
36+
module.exports = ProcessUpEvents;

0 commit comments

Comments
 (0)