Jump to content

SpriteBatch vs DisplayObjectContainer


Ezelia
 Share

Recommended Posts

SpriteBatches are always faster but those come with some trade offs.

SpriteBatches only can be 1 layer deep (no children), have no interactions, afaik no filters, the Sprites have to share a base texture, etc.

A DisplayObjectContainer has all pixi features but renders slower.

 

I don't really see why there is no interactions for SpriteBatches tho.

Link to comment
Share on other sites

It can be difficult to know when to use one over the other.

SpriteBatch is *usually* faster, but not always; it depends on your specific use.

I usually start with a DOC and then, if I feel I need to optimize, tinker around with an SB.

Link to comment
Share on other sites

Tints will not work with sprite batch, you have only position, rotation, alpha, and scaling. Anything else is not considered, which is where the speed boost comes from. It uses a much faster shader that forces batching and makes assumptions. The trade off being you don't get the fancy stuff.

Link to comment
Share on other sites

thank you xever,

I also started looking at the source code and I have now a better idea on when I should use it and when not.

 

my first question was because I wanted to use it in a particle emitter I'm making for pixi, but it use tinting a lot. so I'll just stay with DisplayObjectContainers for now :)

Link to comment
Share on other sites

You should still use SpriteBatches for your emitters, at least when it makes sense.

If the current animation is not tinting the particles, then use the SpriteBatch.

I haven't looked into the WebGL SpriteBatch code yet, but for the CanvasRenderer, it is absolutely possible to use SpriteBatch and tint together. You just have to copy the baseTexture frame to a new canvas, create a texture of it, and use that texture for your particle sprites. Whenever you change the tint, you just take the original baseTexture again, tint it, and overwrite your particle texture.

Link to comment
Share on other sites

I'll try that, but not sure if it'll make performance better.

as I already have some performance issues with tinting.

 

actually, the problem is that when I use tinting, I need a new tint each frame or so ! it's used to fade a particle color from a start color to an end color.

and all particles do not share the same tint at a given time.

 

even with DisplayObjectContainer, I forced no cache for tinting because it's useless and make things worst.

 

I maybe need another aproach for the color variation.

Link to comment
Share on other sites

  • 4 weeks later...

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...