Jump to content

[Pixi] What's DisplayObjectContainer for?


d13
 Share

Recommended Posts

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! 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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