d13 Posted May 15, 2014 Share Posted May 15, 2014 Hello! I'm trying to understand how and why to use DisplayObjectContainer and SpriteBatch. - Should they be used to group sprites to make game scenes? - Could they be used to group similar sprites, like enemies or bullets. That way I suppose you could use the `children` property to loop through all their containing sprites. - Why would you use DOC instead of SB? My understanding is that SB is faster, but shouldn't contain nested objects. For games, would it best to default to SB to err on the side of speed? - What makes SB fast? Is it faster to dump sprites in an SB and animate then there, rather than if they were just animated directly on the stage? Or is SB just fast relative to DOC? If any more experienced users chime in with their ideas and workflow scenarios, that would be great! Quote Link to comment Share on other sites More sharing options...
xerver Posted May 15, 2014 Share Posted May 15, 2014 PIXI.js is a scene graph, so a DOC is just a node on the graph that contains children. - Should they be used to group sprites to make game scenes? Yes. - Could they be used to group similar sprites, like enemies or bullets. That way I suppose you could use the `children` property to loop through all their containing sprites. Yes. - Why would you use DOC instead of SB? My understanding is that SB is faster, but shouldn't contain nested objects. For games, would it best to default to SB to err on the side of speed? The reason SB is faster is by dropping support for all the advanced features (masking, tinting, custom rendering, interactivity, etc). There is no "right" one to choose, you choose the one that is the most appropriate for what you are trying to do. If you a displaying a tilemap layer, likely it will be a flat list of tile sprites that do not need advanced features. That is a good case for SB. If you need nested groups to manage organization of sprites, and maybe some are interactive, that is a good case for DOC. - What makes SB fast? Is it faster to dump sprites in an SB and animate then there, rather than if they were just animated directly on the stage? Or is SB just fast relative to DOC? SB is faster because we make assumptions and impose limitations. We assume all children will share a base texture; we assume you will need no more features than position, scale, and rotation; we assume there will only be a single level of children. If all those assumptions are true, then SB is much faster because it doesn't have to do any of the checks or advanced shaders used by DOC. Basically it is a gutted out, stripped down version of DOC so it can just get the iamges to the screen asap. d13 1 Quote Link to comment Share on other sites More sharing options...
d13 Posted May 16, 2014 Author Share Posted May 16, 2014 Thank you so much, Xerver, that's an extremely helpful and clear explanation! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.