'); -->

# Optimizing Performance

Mad Level Manager is written with performance in mind, but there are some bottlenecks that a user can easily fall into. Here you will learn about optimization tricks for Mad Level Manager.

## Enable “Hide Invisible Sprites” Panel option

This one has been introduced in 2.2.7 version and is enabled for all newly created scenes from this point.

If you’re not hacking into how Mad Level Manager is rendering sprites, you most probably want to disable from rendering sprites that are not visible to Camera 2D. To do so, enable Hide Invisible Sprites in your Panel inspector.

## Consider switching to atlases…

Mad Level Manager uses rendering engine called Mad2D. Its flexibility allows a user to choose how he wants 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 by simplicity (just drag and drop texture).

The Atlas Mode can be used in any configuration but it’s 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 a 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 that 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 the order determined by GUI depth. Sprites with the higher depth will be drawn above sprites with the lower depth (will be queued at the end). What about if two sprites have the same depth? They will be rendered in an unspecified order but next to each other. If you can group your sprites with the same texture to have the common depth, then they will be batched!

### Counting Draw Calls

Let’s think of a scene where Mad2D orders a sprite rendering in this order (there are two textures):

In this scenario, the minimum draw call count is 6. That’s because each rendering procedure needs to change the rendering context – the texture. Changing the context means an additional draw call. Simple, isn’t it?

Here, the draw call count is equal to 4. That’s because first two hearts can be painted using one draw call, and 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 configure your icon as above, then no matter how many icons are 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 not to pollute these GUI depth values because the batching process may be broken to smaller chunks.