Added Input.setTopOnly and fixed process handling when topOnly is used with over / out events (#3136)

This commit is contained in:
Richard Davey 2018-01-03 15:09:06 +00:00
parent 8db93c4cb2
commit 98a82e3672
3 changed files with 20 additions and 20 deletions

View file

@ -91,6 +91,8 @@ var SceneInputManager = new Class({
setPollAlways: require('./inc/SetPollAlways'),
setPollOnMove: require('./inc/SetPollOnMove'),
setTopOnly: require('./inc/SetTopOnly'),
setHitArea: require('./inc/SetHitArea'),
setHitAreaCircle: require('./inc/SetHitAreaCircle'),
setHitAreaEllipse: require('./inc/SetHitAreaEllipse'),

View file

@ -11,8 +11,17 @@ var ProcessOverOutEvents = function (pointer)
var stillOver = [];
var previouslyOver = this._over[pointer.id];
if (this.topOnly && currentlyOver.length)
{
this.sortGameObjects(currentlyOver);
// Only the top-most one counts now, ignore the rest
currentlyOver.splice(1);
}
// Go through all objects the pointer was previously over, and see if it still is.
// Splits the previouslyOver array into two parts: justOut and stillOver
for (i = 0; i < previouslyOver.length; i++)
{
gameObject = previouslyOver[i];
@ -29,7 +38,7 @@ var ProcessOverOutEvents = function (pointer)
}
}
// Go through the hit test results (the contents of currentlyOver)
// Go through all objects the pointer is currently over (the hit test results)
// and if not in the previouslyOver array we know it's a new entry, so add to justOver
for (i = 0; i < currentlyOver.length; i++)
{
@ -45,25 +54,6 @@ var ProcessOverOutEvents = function (pointer)
// By this point the arrays are filled, so now we can process what happened...
// In a topOnly situation a new justOver entry at the top
// should clear all previous justOut entries and ignore the rest of the stillOver entries
if (this.topOnly && justOver.length)
{
this.sortGameObjects(justOver);
// Only the top-most one counts now, ignore the rest
var topObject = justOver.shift();
console.log('topOnly', topObject.name);
justOver = [ topObject ];
justOut = justOut.concat(stillOver);
stillOver.length = 0;
}
// Process the Just Out objects
var total = justOut.length;

View file

@ -0,0 +1,8 @@
var SetTopOnly = function (value)
{
this.topOnly = value;
return this;
};
module.exports = SetTopOnly;