Cocos2d-x 3.2 Monopoly game project development-Part 9 code optimization, cocos2d-x Project Development
Perform code optimization according to the following three points:
1. Now, click the level of the ocean world and call the addPlayerAnimation () method to cache all the animations required by the role to the memory. This animation is related to the role, therefore, you should add the role animation to the RicherPlayer class. When a role exits the game, it is easy to clean up, and easy to manage and call.
2. When the role startGo () is called, it will be called to the RicherGameController class. However, every time we call RicherGameController, we will create an object.
3. The RicherGameController class should only process logic-related data. For other logically unrelated data, we should try to transfer it to the corresponding class for processing.
For the first point:
Remove the method void GameBaseScene: addPlayerAnimation () from the GameBaseScene to the RicherPlayer class. In this case, you also need to modify the create method of RicherPlayer, input a tag for the create method of RicherPlayer, and reference the corresponding image to create a role based on the tag.
For the second point:
Change RicherGameController to singleton
For the third point:
Remove the Code created from the animation and move it to the RicherPlayer class for processing.
After that, we can use beyondCompare to compare the differences between the two projects. The logic is much better than before.
Click to download code http://download.csdn.net/detail/lideguo1979/8296883
To be continued ......................