Cocos2d-x 3.2 Monopoly game project development-Part 9 code optimization, cocos2d-x Project Development

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.