BeachBum Posted September 18, 2014 Share Posted September 18, 2014 I'm using a particle emitter but it seems the same as group sorting, let me know if I'm wrong on that. I see how to sort a group by x or y but I'm trying to sort by scale like this:getLargest: function(emitr) { emitr.sort('scale.x', Phaser.Group.SORT_ASCENDING) return emitr.getTop(); }I'm not sure what right is but that is wrong, it throws an error in Phaser.js "Cannot read property 'z' of undefined" Thanks for any help! Link to comment Share on other sites More sharing options...
lewster32 Posted September 18, 2014 Share Posted September 18, 2014 You'll have roll your own sort routine I'm afraid - though the Group.sort method is just a wrapper for JavaScript's Array.sort, so you could do something like this:emitr.children.sort(function(a, { if (a.scale.x < b.scale.x) { return -1; } else { return 1; }}); Link to comment Share on other sites More sharing options...
BeachBum Posted September 19, 2014 Author Share Posted September 19, 2014 That makes sense, I actually got that working and then realized I could go a little faster by just doing a one pass comparison and taking the biggest one. No sense in sorting then all when I only need one. Link to comment Share on other sites More sharing options...
lewster32 Posted September 19, 2014 Share Posted September 19, 2014 Sorting will change the display depths of the objects, which was what I was assuming you were doing as well, but never mind Link to comment Share on other sites More sharing options...
Recommended Posts