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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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