Cocos2d-x homemade tool 07: printing cocos2d-x node tree

Source: Internet
Author: User

Cocos2d-x is based on the node tree rendering 2D engine and a method of drawing with commands, which is very common in the era of function machines ).

However, the node tree is a magic horse, and the node tree is a magic horse concept. Recently there are a lot of books on the market of cocos2d-x, if you have the honor to buy a book, the above will write about because of opengl drawing method xxx, So we xxx, then xxx. Well. But this is very abstract. Not intuitive.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140112/2100192L8-0.jpg "title =" 6c19279ejw1e5iax5067jj207o052t8l.jpg "alt =" wKiom1LOpcWxEtyTAAA-t9BRE60319.jpg "/>


In addition, the node tree engine is defective when debugging the drawing position. Because it uses all relative coordinates, you often don't know where to draw things, whether to run outside the screen or be covered by the magic horse. This is not as intuitive as the code drawn in command mode.

In order to allow you to see the tree, and to facilitate debugging of the drawing position. I made a simple code and can output the entire tree on the console. Of course, you can choose the root node. The Code is as follows:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140112/2100191P6-1.jpg "title =" 6c19279ejw1e5iazkupjyj20im0jodhv.jpg "alt =" wKioL1LOpjbwRGbSAAIdNChTGG4300.jpg "/>

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140112/2100191250-2.jpg "title =" empty "alt =" wKiom1LOplyTslP5AAFb9PRkqqw392.jpg "/>

It is easy to recursively output, and then we only need to print the output variable s.

However, note that there may be re-sorting of subnodes during rendering. To ensure that the output result is correct, force re-sorting first.

The following is the call code:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140112/21001911a-3.jpg "title =" 6c19279ejw1e5ib6wjtyjj20ct02kglk.jpg "alt =" wKioL1LOppqBFUR3AABGYtVK55k643.jpg "/>


Let's print the node tree in the helloworld example. The output result is as follows:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140112/21001a2L-4.jpg "title =" 6c19279ejw1e5ib8ma16hj20hm049t97.jpg "alt =" wKiom1LOpsihKfKHAACw9MB_ttQ854.jpg "/>

This code can be used for many functions. Of course, you can expand it yourself.


Download the code below: (engine version 2.13)

This article is from the "Old G hut" blog, please be sure to keep this source http://4137613.blog.51cto.com/4127613/1350243

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.