Cocos2dx game development simple getting started video tutorial (cocos2d-x)-3rd days

Source: Internet
Author: User

 

 

1. Data Structure Selection

// The efficiency of array insertion and deletion is low; the efficiency of searching and traversing is high.
// High efficiency of list insertion and deletion; low efficiency of searching and traversing
// Add or delete: the number of collisions between monsters and darts is small.
// Traversal: it takes more than 1.0 fps for a traversal.
// Select array

2. Collision Detection Functions

 

 
void HelloWorld::update(float delta) // delta = 1.0 / fps{CCArray* targetToDelete = new CCArray;CCArray* projToDelete = new CCArray;CCObject* itarget;CCObject* iproj;CCARRAY_FOREACH(_targets, itarget){CCSprite* target = (CCSprite*)itarget;CCRect targetZone = CCRectMake(target->getPositionX(),target->getPositionY(),target->getContentSize().width,target->getContentSize().height);CCARRAY_FOREACH(_projs, iproj){CCSprite* proj = (CCSprite*)iproj;CCRect projZone = CCRectMake(proj->getPositionX(),proj->getPositionY(),proj->getContentSize().width,proj->getContentSize().height);if (projZone.intersectsRect(targetZone)){projToDelete->addObject(iproj);targetToDelete->addObject(itarget);}} // end of iterate projectile} // end of iterate targetCCARRAY_FOREACH(projToDelete, iproj){_projs->removeObject(iproj);CCSprite* proj = (CCSprite*)iproj;proj->removeFromParentAndCleanup(true);}CCARRAY_FOREACH(targetToDelete, itarget){_targets->removeObject(itarget);CCSprite* target = (CCSprite*)itarget;target->removeFromParentAndCleanup(true);}targetToDelete->release();projToDelete->release();}

Note: You cannot delete a Member from CCArray while traversing CCArray.

 

 

3. Use CCSprite-> setTag (int)

In this way, different genie can be marked to distinguish them.

 

 

 

Uploaded to Youku

 

Http://v.youku.com/v_show/id_XNjY0MjEzNzI0.htmlLesson 1

Http://v.youku.com/v_show/id_XNjY0MjMzMzYw.html 2nd

Http://v.youku.com/v_show/id_XNjY0MjU1OTcy.html 3rd

Http://v.youku.com/v_show/id_XNjY0MzQxMDE2.html 4th

Http://v.youku.com/v_show/id_XNjY1MTI3NjYw.html 5th

Http://v.youku.com/v_show/id_XNjY1MTI5ODQw.html 6th

 

 

Please download HD from Baidu online storage.


Reprinted please indicate the source: http://blog.csdn.net/xingxiliang/article/details/18557631

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.