Skip to content

Commit 98a82e3

Browse files
committed
Added Input.setTopOnly and fixed process handling when topOnly is used with over / out events (phaserjs#3136)
1 parent 8db93c4 commit 98a82e3

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

v3/src/input/local/SceneInputManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ var SceneInputManager = new Class({
9191
setPollAlways: require('./inc/SetPollAlways'),
9292
setPollOnMove: require('./inc/SetPollOnMove'),
9393

94+
setTopOnly: require('./inc/SetTopOnly'),
95+
9496
setHitArea: require('./inc/SetHitArea'),
9597
setHitAreaCircle: require('./inc/SetHitAreaCircle'),
9698
setHitAreaEllipse: require('./inc/SetHitAreaEllipse'),

v3/src/input/local/inc/ProcessOverOutEvents.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ var ProcessOverOutEvents = function (pointer)
1111
var stillOver = [];
1212
var previouslyOver = this._over[pointer.id];
1313

14+
if (this.topOnly && currentlyOver.length)
15+
{
16+
this.sortGameObjects(currentlyOver);
17+
18+
// Only the top-most one counts now, ignore the rest
19+
currentlyOver.splice(1);
20+
}
21+
1422
// Go through all objects the pointer was previously over, and see if it still is.
1523
// Splits the previouslyOver array into two parts: justOut and stillOver
24+
1625
for (i = 0; i < previouslyOver.length; i++)
1726
{
1827
gameObject = previouslyOver[i];
@@ -29,7 +38,7 @@ var ProcessOverOutEvents = function (pointer)
2938
}
3039
}
3140

32-
// Go through the hit test results (the contents of currentlyOver)
41+
// Go through all objects the pointer is currently over (the hit test results)
3342
// and if not in the previouslyOver array we know it's a new entry, so add to justOver
3443
for (i = 0; i < currentlyOver.length; i++)
3544
{
@@ -45,25 +54,6 @@ var ProcessOverOutEvents = function (pointer)
4554

4655
// By this point the arrays are filled, so now we can process what happened...
4756

48-
// In a topOnly situation a new justOver entry at the top
49-
// should clear all previous justOut entries and ignore the rest of the stillOver entries
50-
51-
if (this.topOnly && justOver.length)
52-
{
53-
this.sortGameObjects(justOver);
54-
55-
// Only the top-most one counts now, ignore the rest
56-
var topObject = justOver.shift();
57-
58-
console.log('topOnly', topObject.name);
59-
60-
justOver = [ topObject ];
61-
62-
justOut = justOut.concat(stillOver);
63-
64-
stillOver.length = 0;
65-
}
66-
6757
// Process the Just Out objects
6858
var total = justOut.length;
6959

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var SetTopOnly = function (value)
2+
{
3+
this.topOnly = value;
4+
5+
return this;
6+
};
7+
8+
module.exports = SetTopOnly;

0 commit comments

Comments
 (0)