Jump to content

Group.add adds a copy of the sprite to another group


Serdar
 Share

Recommended Posts

Is this a bug or what? Please see the test code and screenshots below. (using Phaser v2.4.4)

 

This code adds circle to both group1 and group2! It should not, should it?

 

image.png

function preload() {		game.load.image('circle', 'assets/circle.png');	}function create() {		var group1 = new Phaser.Group(game);	var group2 = new Phaser.Group(game);		var mySprite = new Phaser.Sprite(game, 100, 100);	group2.add(mySprite);		var circle = new Phaser.Sprite(game, 10, 10, 'circle');	circle.width = 32;	circle.height = 32;	group1.add(circle);	}

But if I just change the order of group declarations it works as it should be: Only one instance of circle.

 

image.png

function preload() {		game.load.image('circle', 'assets/circle.png');	}function create() {		var group2 = new Phaser.Group(game);	var group1 = new Phaser.Group(game);		var mySprite = new Phaser.Sprite(game, 100, 100);	group2.add(mySprite);		var circle = new Phaser.Sprite(game, 10, 10, 'circle');	circle.width = 32;	circle.height = 32;	group1.add(circle);	}
Link to comment
Share on other sites

The code you're showing in the CodePen is different than what you're highlighting. And I'm not quite sure what the bug is here?

 

In 2.4.3 it looks like since you didn't give it a texture it's not drawing anything; in 2.4.4 it looks like it's defaulting to missing texture unless you explicitly pass in null. Is that the bug you're talking about?

 

How do you know your circle sprite is in both groups?

Link to comment
Share on other sites

No, it's the exact same code! Compare the create and preload functions.

 

You know, CodePen doesn't let you load PNG assets from another domain. But it doesn't matter at all: This is not the bug I am talking about. Just notice in one version there is only 1 green rectangle (drawn in place of the actual PNG) and 2 in the other.

 

Forget about the code here, just compare 2 CodePen pages.

 

Exact same code, different results for v2.4.3 and v2.4.4. Here they are again:

 

Duplicate sprite in v2.4.4: http://codepen.io/anon/pen/rxayzY

Same code works fine in v2.4.3: http://codepen.io/anon/pen/vLExzo

 

How do you know your circle sprite is in both groups?

 

 

Just wait CodePen finishes rendering if you don't see any green rectangles.

Link to comment
Share on other sites

try

mySprite.baseTexture.skipRender=true

otherwise it uses the default texture for the sprite, which  is generally the last texture used i think

 

[update]

actually that doesn't work ... skipRender here, just means both texture's dont show, presumably because they're actually sharing the same texture

http://codepen.io/jmp909/pen/xZGVKy

 

and just to confuse matters, this works now, but only because I've put 2 texture in the cache.. with 1 texture it breaks as you mention

http://codepen.io/jmp909/pen/adONdQ

 

i guess it's a bug then ;)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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