Cocos2d-x 3.0 rc0 + flappybird learning experience

Source: Internet
Author: User

I am a big rookie, just entry cocos2d-x soon, decided to write a little game practice feel, found OiteBoys Article cocos2dx production flappybird, and then learn, used to practice


The author's version is version 3.0 beta, but there is a slight difference in version 3.0 rc0:


1) The onContactBegin parameter of the physical collision is changed to one

// Auto contactListener = EventListenerPhysicsContact: create (); contactListener-> onContactBegin = CC_CALLBACK_1 (GameLayer: onContactBegin, this); this-> getEventDispatcher () -> addEventListenerWithSceneGraphPriority (contactListener, this );

Listener Function

bool GameLayer::onContactBegin(PhysicsContact& contact) {this->gameOver();return true;}




2. body Parameters


Add the following attributes when adding the body to the bird and pipe. Otherwise, the onContactBegin function is not triggered.

        body->setCategoryBitmask(1);    // 0001body->setContactTestBitmask(-1); // 0100body->setCollisionBitmask(-1);   // 0011


Then there is a tiny bug in the author's code, that is, after clicking retartBtn, the bird will disappear immediately after the collision, rather than disappear after the landing. The solution is to set the bird to the singleton mode.

Use normal CREATE_FUNC ().


Appendix:


Flappybird source code



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.