Jump to content

SpriteBatch optimization


qdrj
 Share

Recommended Posts

I'm tuning performance for my game. I'm using SpriteBatches where it is possible.

 

So I have looked at PIXI sources(version 2.2.8) and made next assumptions about SpriteBatch performance:

 

WebGL: Inside each SpriteBatch I should use textures only from one spritesheet. Otherwise on each render WebGLFastSpriteBatch.flush is called which is expensive operation and should be avoided.

 

Canvas: SpriteBatch children can be from different spritesheets it won't affect performance. But we should avoid child rotation because it would call context.setTransform multiple times.

 

Overall: Using sb for canvas improves performance very slightly. For WebGL it gives significant boost. 

 

 

Please correct me if I wrong. Thanks in advance!

 

Link to comment
Share on other sites

 

Thats pretty much it, I wouldn't try to use them differently based on renderer though. Flat array of children, only basic transforms, and share a spritesheet. If you do those it will be faster (especially using ParticleContainer in v3).

 

What are basic transformations? Which transforms are more expensive than others?

Link to comment
Share on other sites

What are basic transformations? Which transforms are more expensive than others?

Translate, Scale, Rotate are the basic transformations.

Translate and Scale are the cheapest, Rotate is slightly more expensive because of the sinus/cosinus calculation.

Non basic would probably be something like shear/skew.

Also alpha and the visible property should work fine in SpriteBatches,

not sure if tint is supported in the ParticleContainer of v3.

The ParticleContainer in v3 allows us to define which properties of the Sprite we wish to upload to the GPU.

If your Batch never uses scale, you can disable it.

If it never uses the alpha property, you can disable it.

etc.

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