Cocos2dx & amp; Lua, cocos2dx Official Website

Source: Internet
Author: User

Cocos2dx & Lua, cocos2dx Official Website

GUIReader has a widgetFromJsonFile method. This method is used to parse the json file (the UI generated by cocostudio) and return the parent node (Widget) of the file ), then, it facilitates further UI operations (such as obtaining various sub-classes for filling data for display ).


The problem arises at this time. When a page or a control (especially page flip, list, etc.) is required, A large number of nodes need to be loaded (all obtained by separate json parsing). This kind of loading will make the mobile phone very painful (about 30 K, when the number of loaded nodes reaches 50, it will get stuck in 2 ~ 3 seconds ).


Therefore, optimization is required here.

In fact, the optimization idea is quite simple. First, find the problem: since time is spent parsing a large number of json files, that is to say, here, the parsed json is one-to-one correspondence with the data set you need to display. Simply put: the reason for the card is that you have several pieces of data to parse json several times (many people will do this because they directly fill in the parsed widget class ). After optimization, you will think this is very inappropriate.


Therefore, we can easily conclude that we need to unparse this json file before filling in the data and binding it to it!


Idea: parse only the minimum number of subnodes that can be displayed on the current page (or controls, especially page flip) (this is required now, because the same subnode can have only one root node), and then the parsed node (widget) is put in a data structure (queue or array are customized as needed ); (Here we will explain: If a game has a recruitment function for ten connections, each recruitment will display ten cards on a page. The display optimization here is as follows: the node class that loads 10 cards at login is placed in a data structure. After each recruitment, We need to parse the json displayed on the following page (we do not recommend adding 10 static cards here, because the file will become larger and the data will be bound to the UI operation as before), so every time the display is retrieved and filled with data from the data structure, it is added to the page ). After optimization, for example, if a player clicks 10 times for 10 times, I just Parsed the json x 10 + 10 card json for one page, instead of (1 page json + 10 card json) * 10;


The cost of time optimization is a certain amount of memory space. Of course, this is the absolute value.

In the future, I will write some implementations to help you better understand the ideas here.




Cocos2dx and cocos2d game development which is better?

So don't think about it, it must be cocos2dx, because cocos2d can only develop ios games, can not be transplanted to android, because cocos2d is OC language, cocos2d-x is not the same, it is written in c ++ and can be well implemented across platforms. The advantages of these two items are the same. You can achieve good animation effects without using OpenGL code, and it is easy to learn. forums and blogs in this area are everywhere, you can use it with confidence. Disadvantages I think that if I want to implement cross-platform requests, I need to work harder on network requests. In the past, I spent some time doing this. cross-platform network request libraries are hard to find, previously Used cURL. You can try it.
Cocos2dx is a tool for cocos2d porting. The functions in cocos2dx are similar, but cocos2dx is written in c ++ and cocos2d is written in OC. Therefore, the code format remains quite different. The operation interface is the same. There are basic concepts such as directors, scenes, layers, and genie. Therefore, it is a principle. As long as these concepts are passed, others are the writing issues.

Cocos2dx and cocos2d game development which is better?

So don't think about it, it must be cocos2dx, because cocos2d can only develop ios games, can not be transplanted to android, because cocos2d is OC language, cocos2d-x is not the same, it is written in c ++ and can be well implemented across platforms. The advantages of these two items are the same. You can achieve good animation effects without using OpenGL code, and it is easy to learn. forums and blogs in this area are everywhere, you can use it with confidence. Disadvantages I think that if I want to implement cross-platform requests, I need to work harder on network requests. In the past, I spent some time doing this. cross-platform network request libraries are hard to find, previously Used cURL. You can try it.
Cocos2dx is a tool for cocos2d porting. The functions in cocos2dx are similar, but cocos2dx is written in c ++ and cocos2d is written in OC. Therefore, the code format remains quite different. The operation interface is the same. There are basic concepts such as directors, scenes, layers, and genie. Therefore, it is a principle. As long as these concepts are passed, others are the writing issues.

Related Article

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.