Tower defense game performance optimization sharing

background:

Recently, due to the relationship between new coronary pneumonia, the company has done a lot of content related to expectations. In fact, one is a tower defense game, which is about building turrets on a fixed route to resist viruses and prevent each virus from entering the body.

That's fine. Why should there be optimization? The requirement is only to run normally on some high-end PCs, and the time requirement is very tight. It takes only two days to complete one person, including planning, art, programming, and numerical work.

So I hit my mechanical keyboard madly for two days and it was done.
Then I received a need, which needs to be run on the Android platform...
and then optimized the following aspects.
Insert picture description here

In terms of resources:
1. The virus model is changed from the original high mode to the low mode.
2. The 3D model scene is replaced by a plane, there is no way to have a scene with thousands of faces.
3. The three-dimensional bacteria running path channel and the human body are reduced and set as static objects.
4. Try to deal with messy pictures to a multiple of 2.
5. Adjust the special effects placed at will and adjust the number of special effects emitted.
6. The pictures with this special effect are also very big and need attention.
7. Some pictures have the read-write function checked, so pay attention to adjustment.
8. Unify some fonts, try to use one or two fonts, and some fonts only import letters or numbers.
9. Set up picture packing to pack the atlas to reduce dragcall.

"Code aspect"
1. Create object pools for monsters and bullets, add them if they are not enough.
2. Write frequently used variables outside of Update to reuse the same piece of memory.
3. Whether the foreach used can be replaced with for.
4. To keep the speed stable, set the target frame rate to a fixed value of 60.
5. Change the use of Animation to control the action path of the virus to use frame movement, because the monster position obtained by Animation will be incorrect.
6. Change the algorithm of the turret angle calculated by Atan2 to transform.forward.
7. Play high-frequency sound effects such as bullets and explosions at limited intervals.
8. After each wave, call GC once to clean up part of the memory.

Finally it can run normally on the Android platform.
I don't know if it will help you, and I hope to know some further optimization knowledge.

Guess you like

Origin blog.csdn.net/ww1351646544/article/details/104931465