Cocos2d-x the way the elves move

Source: Internet
Author: User

1. Aircraft Launch Bullet type

To achieve the flying effect of the bullet, and do not want to calculate the location in each frame update, the best way to call Ccmoveto

When a bullet is fired, it can be Cctouchbegan:

ccmoveto* move = Ccmoveto::create (0.4f, CCP (_plane->getposition (). X+WINSIZE.WIDTH/4, _plane->getposition (). Y) );//range is 1/4 of the screen, starting point is the position of the aircraft, 0.4 seconds to complete the range _bullet->runaction (move, cccallfuncn::create (this, Callfuncn_selector (Baselayer::bulletremove)), (NULL)); When the bullets are finished, remember to destroy them.

The way to destroy bullets depends on project, which is my own project notation:

void Baselayer::bulletremove (ccnode* spend) {ccsprite* sprite = (ccsprite*) spend;//convert the Ccnode transferred to a bullet//destroy the bullet from the array _ Bulletarray->removeobject (Sprite, True); _batchnode->removechild (Sprite, True); Actually destroy the bullet from the batch node.

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: 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.