Ezelia Posted August 28, 2014 Share Posted August 28, 2014 Hi, juste curious about the main difference between SpriteBatch and DisplayObjectContainer. is SpriteBatch allways faster ? or there are some cases where DisplayObjectContainer remain preferable ? Quote Link to comment Share on other sites More sharing options...
Sebi Posted August 28, 2014 Share Posted August 28, 2014 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. Quote Link to comment Share on other sites More sharing options...
d13 Posted August 28, 2014 Share Posted August 28, 2014 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. Quote Link to comment Share on other sites More sharing options...
Sebi Posted August 28, 2014 Share Posted August 28, 2014 In which case is a SpriteBatch slower than a DOC? A SpriteBatch is made for extremely fast rendering (positions, rotations, alpha, scale), it should never be slower than a DOC. Quote Link to comment Share on other sites More sharing options...
Ezelia Posted August 28, 2014 Author Share Posted August 28, 2014 Thank you Sebastian I can see the difference now ! I'm making some tests .... and sprite tinting don's seem to be working with SpriteBatch btw Quote Link to comment Share on other sites More sharing options...
xerver Posted August 29, 2014 Share Posted August 29, 2014 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. Quote Link to comment Share on other sites More sharing options...
alex_h Posted August 29, 2014 Share Posted August 29, 2014 I found that if the sprite being drawn comes from a texture atlas then SpriteBatch is also slower. It works best when drawing a single complete image file, not a rect from an image. Quote Link to comment Share on other sites More sharing options...
Ezelia Posted August 29, 2014 Author Share Posted August 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
Sebi Posted August 29, 2014 Share Posted August 29, 2014 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. Quote Link to comment Share on other sites More sharing options...
Ezelia Posted August 29, 2014 Author Share Posted August 29, 2014 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. Quote Link to comment Share on other sites More sharing options...
agamemnus Posted September 23, 2014 Share Posted September 23, 2014 Would it be possible to add .pivot to SpriteBatch? (isn't it just a recalculation of position?) 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.