threedollarbill Posted May 7, 2016 Share Posted May 7, 2016 Hi, I am fairly new to Phaser (formerly a Flash dev) and I am currently trying to decide whether I should use a Sprite or a Group. Since they can both be used as a container, I am trying to figure out which one of the two I should use. For my purpose, I simply want to have 3 separate main "screens" / "containers" (stage select screen, game screen, and win / lose screen). I plan on setting their visibility on / off, and possibly tweening them in and out of view too for a fancy transition-effect when switching between the screens. My question is what would be better to use for this. Sprites or Groups? What would be the benefits or hindrances of each? Link to comment Share on other sites More sharing options...
drhayes Posted May 9, 2016 Share Posted May 9, 2016 You probably want group for that... although you should also check out States. They're not a display object container, but more of a logical "what's going on in my game now" kind of construct. As far as group vs. sprite: groups have iteration and filtering methods like getFirstAlive and callAllExists, helpful in manipulating a large set of things. Link to comment Share on other sites More sharing options...
kbtpodifo Posted May 10, 2016 Share Posted May 10, 2016 I don't think it is possible to rearrange which children are on top of others with Phaser.Sprite. It is possible with Phaser.Group. Link to comment Share on other sites More sharing options...
drhayes Posted May 10, 2016 Share Posted May 10, 2016 It is possible, sort of. The primary texture of the Sprite is pretty much always going to be on top because it is the root of the display tree -- it's "above" all of its children. If you don't add a primary texture then you can position the children all you want with "bringToTop" and "addChildAt", etc. Link to comment Share on other sites More sharing options...
kbtpodifo Posted May 10, 2016 Share Posted May 10, 2016 11 minutes ago, drhayes said: It is possible, sort of. The primary texture of the Sprite is pretty much always going to be on top because it is the root of the display tree -- it's "above" all of its children. If you don't add a primary texture then you can position the children all you want with "bringToTop" and "addChildAt", etc. Okay thanks for the clarification. Link to comment Share on other sites More sharing options...
glantucan Posted June 6, 2016 Share Posted June 6, 2016 It seems the difference is deeper. For example the width and height properties of a sprite will always report the size of its texture, ignoring completely the size and position of its children. I recently discovered I was trying to use them as containers (Old habits never die, I also have to unlearn actionscript) on a big project and have to change all that in order to enable scalable relative positioning in my game. So I would use groups for anything that is a container in your game. drhayes 1 Link to comment Share on other sites More sharing options...
stupot Posted June 9, 2016 Share Posted June 9, 2016 I now always use groups because I nearly always ended up having to convert them, mostly because I wanted to toggle the visibility of the base sprite without it affecting the children (which I thought I wouldn't want to do at the start). Link to comment Share on other sites More sharing options...
Recommended Posts