Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created October 16, 2012 23:08
Show Gist options
  • Save beckyconning/3902652 to your computer and use it in GitHub Desktop.
Save beckyconning/3902652 to your computer and use it in GitHub Desktop.
//else we search for an entity with Mouse component
if (!closest) {
q = Crafty.map.search({ _x: x, _y: y, _w: 1, _h: 1 }, false);
for (l = q.length; i < l; ++i) {
if (!q[i].__c.Mouse || !q[i]._visible) continue;
var current = q[i],
flag = false;
//weed out duplicates
if (dupes[current[0]]) continue;
else dupes[current[0]] = true;
if (current.mapArea) {
if (current.mapArea.containsPoint(x, y)) {
flag = true;
}
} else if (current.isAt(x, y)) flag = true;
if (flag && (current._z >= maxz || maxz === -1)) {
//if the Z is the same, select the closest GUID
if (current._z === maxz && current[0] < closest[0]) {
continue;
}
maxz = current._z;
closest = current;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment