vspinnet Posted March 29, 2016 Share Posted March 29, 2016 I have 3 different types of sprites in a group. I want to sort by "y" then by sprite type when sprites have the same "y" value. Is this possible? Also, if I add sprites A, then sprites B, then sprites C to the group, and then execute the following, will the sort order be by "y", then in order of which sprites where added to the group first to last? group.sort('y', Phaser.Group.SORT_ASCENDING); Link to comment Share on other sites More sharing options...
Tom Atom Posted March 29, 2016 Share Posted March 29, 2016 Hi, use customSort method in Phaser.Group class. You have to pass your own sortHandler to it. Handler is your custom function and Phaser passes two objects (a and b ) to it - it is up to you to do your custom comparsion in it and return result (from source comment: "It should return -1 if `a > b`, 1 if `a < b` or 0 if `a === b`" vspinnet 1 Link to comment Share on other sites More sharing options...
vspinnet Posted March 29, 2016 Author Share Posted March 29, 2016 Thanks. I did notice the custom sort but I couldn't figure out how to "properly" apply a type property to the sprite. Is it as simple as doing this? var sprite = new Sprite(game, 0, 0, "character", 0); sprite.type = 1; Link to comment Share on other sites More sharing options...
Tom Atom Posted March 30, 2016 Share Posted March 30, 2016 Yes, you can create your own class derived from Phaser.Sprite, that will have all additional properties you need (and all sprites will have it) or you can add it dynamically to sprite instance as in your example (and only sprites, you call it on, will have it). vspinnet 1 Link to comment Share on other sites More sharing options...
Recommended Posts