Jump to content

Phaser group.sort is not a function, how to sort group on sprite.data value?


BdR
 Share

Recommended Posts

I'm working on a Phaser3 game with a group of sprites, and I want to sort all the sprites based on the data values. So I tried the code below.

this.bubbles = this.physics.add.group();

for (var i = 0; i < 16; i++) {
	// add random bubble
	var b = Phaser.Math.RND.between(1, 8);
	newbub = this.bubbles.create(0, 0, 'sprites', 'bubble'+b);

	// store color in data
	newbub.setData("color", b);
}
		
this.bubbles.sort("data.values.color"); // TypeError: this.bubbles.sort is not a function

But the .sort() gives this error:

Quote

TypeError: this.bubbles.sort is not a function

It seems the Phaser.Group doesn't have a .sort() function, is that correct? I'm looking at the docs here.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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