Code Style--COCOS2D-X learning process (iv)

Source: Internet
Author: User

1.cocos2d-x has a file "Cocos2d.h" that contains all the other header files. In general, we only need to include this header file when we use it, so we can use the full functionality of the engine.

2.cocos2d-x classes are placed under the Cocos2d namespace. In the game, we often use another macro using_ns_cc provided by the engine to refer to the Cocos2d namespace:

#define USING_NS_CC USING namespace cocos2d.

3. Class naming is consistent with Cocos2d-iphone, consisting of class library abbreviations plus class names, in which class library abbreviations are capitalized, and class names are camel-based. The abbreviation for cocos2d is CC, so cocos2d-x classes have CC prefixes, such as classes that represent actions, called ccaction.

4.cocos2d-x does not use traditional value types, all objects are created on the heap and then referenced by pointers.

There are usually two ways to create a Cocos2d-x object: The first is to create an uninitialized object using the new operator, then invoke the Init series method to initialize it, and the second is to create an object directly using a static factory method.

Both of these methods can create Cocos2d-x objects, but they still have a little bit of a difference in memory management. The object created with the constructor is owned by the caller, and ownership of the object created with the factory method does not belong to the caller, so the object created with the constructor requires the caller to be freed, and the object created using the factory method is not required.

5. In Objective-c, the selector (Selector) is a mechanism similar to a class function pointer in C + +. Because Cocos2d-x inherits the code style of Cocos2d-iphone, it also provides a series of macros similar to those created in the selector syntax in objective-c to create function pointers. These macros have only one parameter, selector, that represents the class method being pointed to.

6. Properties

7. Single case

Code Style--COCOS2D-X learning process (iv)

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.