Jump to content

[SOLVED] How to do a multi sort?


vspinnet
 Share

Recommended Posts

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

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`"

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...