Cocos2dx practice-demo of "legend of war" Learning Experience

Source: Internet
Author: User

[Nagging]

For the source code tutorial, go:Http://blog.csdn.net/iamlazybone/article/details/19612941

Thanks to lazy bones for providing so many demo tutorials, it is really helpful for beginners.

Note:This section only records the experiences of bloggers who have learned the legend of war.


[Game]

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/48/B1/wKiom1QK0eqipZKkAAFxoHOj0cQ894.jpg "Title =" 20131209204757062.jpg" alt = "wkiom1qk0eqipzkkaafxohoj0cq894.jpg"/>



[Learning experience]


1. ccsprite captures small images from a large image

 
//// Ccrectmake is constructed as the UI coordinate, and the origin is in the upper left corner. Ccsprite * sp = ccsprite: Create ("menu.png", ccrectmake (0,0, 120,0 ));//


2. Global variable extern

 
/// Declare in. h: extern ccarray * play_bullet; // defined in. cpp: ccarray * play_bullet = NULL ;//


3. ccmenu Layout

 
/// 1. arrange all buttons in the menu vertically and set the spacing to 20. menu-> alignitemsverticallywithpadding (20); // 2. vertically arranged by menu items and placed each line of Ci elements menu-> alignitemsincolumns (C1, C2, C3 ,..., CN, null );//


4. ccmenuitemtoggle

 
// Ccmenuitemfont * on = ccmenuitemfont: Create ("On"); ccmenuitemfont * off = ccmenuitemfont: Create ("off"); optional * toggle = ccmenuitemtoggle :: createwithtarget (this, menu_selector (options: setoptions), off, on, null); // you can set the toggle-> setselectedindex (1) starting from 0 );//


5. Enable and disable the entire function.

 
//// The largest integer less than or equal to X double floor (Double X); // the smallest integer greater than X double Ceil (Double X );//


6. Random number 0 ~ 1

 
// Ccrandom_0_1 ();//


7. Action Decomposition

When an animation consists of multiple actions, the animation can be decomposed.

For example, it is divided into moving, amplifying, rotating, etc. It is processed separately and then integrated into a complex action.


8. process decomposition

(1) checkiscollide (); // collision detection (blood only)

(2) removeinactiveunit (); // remove inactive elements (destroy dead fighters or ***)

(3) checkisreborn (); // the rebirth of the fighter plane, or the end of the game (re-resurrection)

(4) updateui (); // refresh the interface


9. hybrid mode

Please go to: http://shahdza.blog.51cto.com/2410787/1547633


10. Airplane touch movement

// Void game: cctouchmoved (cctouch * touch, ccevent * event) {If (ship! = NULL) {ccpoint Pos = touch-> getdelta (); // get the offset ccpoint currentpos = ship-> getposition () of the touch screen sliding (); // obtain the current plane coordinate currentpos = ccpadd (currentpos, POS); // The coordinate currentpos = ccpclamp (currentpos, ccpointzero, mysize) after the plane + offset ); // The screen ship-> setposition (currentpos) cannot be removed; // set the coordinates after the plane moves }}//



This article is from the "summer wind" blog, please be sure to keep this source http://shahdza.blog.51cto.com/2410787/1549660

Cocos2dx practice-demo of "legend of war" Learning Experience

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.