Jump to content

Can a sprite only belong to one group?


Dream Of Sleeping
 Share

Recommended Posts

My game keeps crashing. I'm not getting any error message. I was wondering if the problem was my ball sprites belong to two groups. I have groups for each color ball, so I can reuse sprites. But these balls also get added to converyor belts, and when they get added to the conveyor belt I add them to the conveyor belt's ball group. When it falls of the conveyor belt, I remove it from the converyor belt group, and it just disappears off the screen, and then crashes the game.

 

I noticed that when removing a sprite it's group property get set to null, so I thought that's probably the problem. Am I right, and if so any suggestion of a way of pooling the balls and having them grouped for the conveyor belt? I could just use an array, but just wanted to make sure I wasn't missing something.

 

 

 

Link to comment
Share on other sites

  • 1 year later...

So what would be a good approach if you want to have a pool of sprites but have these sprites be part of groups?

 

Would you recommend implementing the pool not as a group but a normal array and manually do the "getFirstExists" functionality to draw killed sprites for reuse?

Link to comment
Share on other sites

Sprites can easily move between Groups. There's no reason why you couldn't maintain one large Group, get the first dead one, then move it to whatever other Group it needs to be in. When it does it could be moved back again.

 

I guess it depends how complex your pool requirements are - because you could equally just code a nice simple little pool yourself - personally I'd either use the above approach, or I'd use a Phaser.ArrayList to manage the pool for me.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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