Dream Of Sleeping Posted February 6, 2014 Share Posted February 6, 2014 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 More sharing options...
Dream Of Sleeping Posted February 6, 2014 Author Share Posted February 6, 2014 Well, the game freezing was because I had nested for loops both using 'i' as a counter, so I caused an infinite loop. It's been months since I've programmed anything so I'm about of practice. lol I would still be intrested to know if it's wrong to add a sprite to more than one group. Link to comment Share on other sites More sharing options...
rich Posted February 6, 2014 Share Posted February 6, 2014 A Sprite can only belong to one Group, yes. But Groups can be nested. I don't know how well you know Flash, but if you do think of it like the way a Sprite could only belong to one DisplayObjectContainer. Same thing. Dream Of Sleeping 1 Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted February 6, 2014 Author Share Posted February 6, 2014 Ok, thanks. Link to comment Share on other sites More sharing options...
fariazz Posted May 7, 2015 Share Posted May 7, 2015 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 More sharing options...
rich Posted May 7, 2015 Share Posted May 7, 2015 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 More sharing options...
fariazz Posted May 7, 2015 Share Posted May 7, 2015 Thanks Richard! the first approach looks good for what I need. Link to comment Share on other sites More sharing options...
Recommended Posts