Basic operations for Cocos2d-X data, actions, messages

Source: Internet
Author: User
Create method for adding a class: create_func (classname) You can use this macro to add a create method for the class. Class: Create () is used to create class objects. The class initialization Call Sequence defined in the macro create_func is constructor and init. Set this class object to autorelease, which means that the objects created with create do not need to be manually deleted. However, this object must be retained for operations such as scenario switching. This requires the retain () function. Of course, when using it, you need to be responsible for memory management and manually delete it. Data Binding: cc_synthesize_readonly (vartype, varname, funname) use this macro to automatically create get and set methods. Overall framework structure: Action usage: actions are attached to characters (genie. Use the three-step action. 1. Find the appropriate genie. 2. Edit the action. 3. genie running actions. The struct class has the following structure. Actions can be divided into transient actions (base-class ccactioninstanse) and delayed actions (base-class ccactioninterval ). You can directly declare a ccfinitetimeaction pointer for the operation, which saves the effort to identify the specific action type, although it is quite easy to remember. Generally, the genie uses runaction to execute the action. When multiple actions are executed sequentially, Sprite-> runaction (ccsquence: Create (act1, Act2 ,..., null); callback action: it is a real-time action, that is, cccallfuncn in ccactioninstant. When used, the first parameter is this. Select the corresponding callback for the second parameter. Set background: When initializing a layer, use cclayercolor: initwithcolor (ccc4 (R, G, B, )); Callback Function: callfuncn_selector and other methods for conversion type. Some function parameters are defined as callback. (To achieve Asynchronization ?) Its type is se_xxx. In this way, we need to change the type of the corresponding function. You can use this macro to change a common function to a callback function. Wizard display and hide: layer-> addchild (), layer-> removechild (). Scheduled function call (in Layer): layer-> schedule (). You can easily customize the call function based on a latency. Touch-screen message Response: In scene: usually used for the response in the menu. In layer: used to respond to an action. 1. Call settouchenabled (true) to receive click messages. 2. Rewrite response
Events (ccset * ptouches, ccevent * pevent); // cctouchesmoved (ccset * ptouches, ccevent * pevent); // drag the cctouchesended (ccset * ptouches, ccevent * pevent); // The end event of the touch screen.
Method for obtaining coordinates: cctouch * Touch = (cctouch *) (touches-> anyobject (); ccpoint location = touch-> getlocation ();
Data Structure: ccarray. Use the macro-simplified for loop of ccarray_foreach (m_abc, it. For_each for CC. Point, square CCP (x, y) returns a ccpoint. Ccrectmake (X, Y, width, height) returns a ccrect. Collision Detection: recta. intersectsrect is used to determine whether two squares have intersection. Play Music: cocosdenshion: simpleaudioengine: sharedengine ()-> playbackgroundmusic (); // background music cocosdenshion: simpleaudioengine: sharedengine ()-> playeffect (); // action effect music Scenario creation: the scenario must inherit from ccscene. First, call the ccscene: Init () function in its initialization function. Then, addchild is called to add a layer to it. Action delay: ccdelaytime: Create (n ). Delay action, which ends after n seconds. Switch scenario: ccdirector: shareddire()-> replacescene (scene ). Change scenario.

This blog is from
Ashuldo
, Reprinted please indicate the source:
Http://blog.csdn.net/fansongy/article/details/8810555

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.