Mad Level Manager is written with performance in mind, but there are some bottlenecks that user can easily fall into. Here you will learn about optimization tricks for Mad Level Manager.
Consider switching to atlases…
Mad Level Manager uses rendering engine called Mad2D. It flexibility allows user to choose how he want to work with Mad Level Manager level select screens. There are two rendering modes:
- Textures Mode
- Atlas Mode
The Textures Mode can be used when you’re creating a game for platforms other than mobiles. It can be used with mobiles too, but with a caution (I will tell why in a moment). It is characterized with simplicity (just drag and drop texture).
The Atlas Mode can be used in any configuration, but it a little more difficult to setup. You have to setup an atlas and keep it up to date. This mode is recommended for mobile devices, because it generates significantly smaller number of draw calls (down to 1).
Or keep things ordered
You can stick to Textures Mode all the time and keep low number of draw calls at the same time. Here’s how to do it.
Unity3D features something that is called dynamic draw call batching. In simple words it checks if objects in render queue can be drawn using only one draw call, and this is true if objects are using the same material. Mad Level Manager is using one material per texture. This means if you can queue sprites with the same texture next to each other, then the draw will be batched. How to do that?
Mad2D draw engine is drawing all sprites in order determined by GUI depth. Sprites with higher depth will be drawn above sprites with lower depth (will be queued at the end). What about if two sprites have the same depth? They will be rendered in unspecified order, but next to each other. If you can group your sprites with the same texture to have common depth, then they will be batched!
Counting Draw Calls
Let’s think of a scene, where Mad2D will order sprite rendering in this order (there are two textures):
In this scenario minimum draw call count is 6. That’s because each rendering procedure needs to change the rendering context – the texture. Changing the context means additional draw call. Simple?
Here draw call count is equal to 4. Thats because first two hearts can be painted using one draw call, next two slots is another draw call. Last two icons will generate two draw calls, because they are different. That’s 4 in total.
This is the best possible configuration, because three hearts can be merged into one, as good as three following slots. Number of draw calls here is 2.
Level Icon Configuration
This knowledge can be applied to how you should configure your level icons. Icons are built of several sprites, so it’s very important to set GUI depths that will allow batch optimization when drawing multiple icons on the same scene.
If you’ll configure your icon as above, then no matter how many icons there will be on your level select screen, all background will be drawn in just one draw call. The same applies to level numbers, lock icons, and stars. If you’re placing other sprites than icons on your level select screens, remember to not pollute these GUI depth values, because it may break the batching process to smaller chunks.